黑马程序员技术交流社区

标题: 关于泛型中的问题 [打印本页]

作者: 12560zhang    时间: 2014-3-4 08:37
标题: 关于泛型中的问题
  1. public class GenericDemo {
  2.          
  3.         public static void main(String[] args) {
  4.                 Demo<String> d=new Demo<String>();
  5.                 d.show("adsf");
  6.                
  7.                 d.print(5);
  8.                 d.print("asd");               
  9.                
  10.                 d.method(5);
  11.                 Demo.method(6);       
  12.                 }
  13. }
  14. class Demo<T>{
  15.         public void show(T t){
  16.                 System.out.println("show:"+t);
  17.         }
  18.         public <Q> void print(Q q){
  19.                 System.out.println("print:"+q);
  20.         }
  21.         public static <W> void method(W t){
  22.                 System.out.println("method:"+t);
  23.         }
  24. }
复制代码


d.method()和Demo.method()有区别吗,
作者: 上官睿鹏    时间: 2014-3-4 11:08
是关于泛型问题,还是静态方法调用的问题啊?
method()前面有修饰符static是个静态方法可以通过类名直接调用。如果前面没有static,那只能通过对象来调用d.method().




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2