Monday, 1 February 2016

Can static methods generic?


Yes, static method can be generic.


classGenericStaticMethod {
      
    static <T> T method(T t) {
        return t;
    }

    public static voidmain(String[] args) {
       String s=GenericStaticMethod.<String> method("static generic");
       System.out.print(s);
    }
}

Output:
     static generic

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...