public interface IMessage<T> {
public void print(T message);
public static final String name ="dsfsdf";
}
//可以这样实现
public class MessageImpl implements IMessage<String> {
@Override
public void print(String message) {
}
}
//也可以这样实现
public class MessageImpl<T> implements IMessage<T> {
@Override
public void print(T message) {
}
}
泛型方法
public class test {
public static void main(String [] args) {
Integer [] arr = getArr(1,2,3,5,4,5);
for (int temp : arr) {
System.out.println(temp);
}
}
//<T>描述的是泛型标记的声明
public static <T> T [] getArr(T ... args) {
return args;
}
}