Wednesday 4 May 2016

Static methods can be generic

  1. class Test {
  2.   static <T> T identity(T t) {
  3. return t;
  4. }
  5. public static void main(String[] args) {
  6. String s = Test.<String> identity("Hi");
  7. System.out.print(s);
  8. }
  9. }

No comments:

Post a Comment