package cn.itcast_05;

public class ObjectToolDemo {
public static void main(String[] args) {
// ObjectTool ot = new ObjectTool();
// ot.show("hello");
// ot.show(100);
// ot.show(true);

// ObjectTool<String> ot = new ObjectTool<String>();
// ot.show("hello");
//
// ObjectTool<Integer> ot2 = new ObjectTool<Integer>();
// ot2.show(100);
//
// ObjectTool<Boolean> ot3 = new ObjectTool<Boolean>();
// ot3.show(true);

// 如果能使用,那就说明泛型类是没有问题的
// 但是呢,谁说了我的方法要和类的类型一致呢?
// 我要是类上没有泛型的话,方法还能不能接收任意类型的参数了呢?
ObjectTool ot = new ObjectTool();
ot.show("hello");
ot.show(100);
ot.show(true);
}
}



package cn.itcast_05;

//public class ObjectTool<T> {
// // public void show(String s){
// // System.out.println(s);
// // }
// //
// // public void show(Integer i){
// // System.out.println(i);
// // }
// //
// // public void show(Boolean b){
// // System.out.println(b);
// // }
//
// public void show(T t){
// System.out.println(t);
// }
//}

/*
* 泛型方法:把泛型定义在方法上
*/
public class ObjectTool {
public <T> void show(T t) {
System.out.println(t);
}
}