Ray's playground

 

Generics(Thinking in Java)

Generic Methods
 1 public class GenericMethods {
 2     public <T> void f(T x)
 3     {
 4         System.out.println(x.getClass().getName());
 5     }
 6     
 7     public static void main(String[] args)
 8     {
 9         GenericMethods gm = new GenericMethods();
10         gm.f("abc");
11         gm.f(123);
12         gm.f(1.5);
13     }
14 }

 

posted on 2010-03-16 21:37  Ray Z  阅读(182)  评论(0编辑  收藏  举报

导航