Monday, 1 February 2016

Can static methods generic?


Yes, static method can be generic.


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

    public static void main(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...