进阶day02-泛型接口的使用
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.inmind.generic_interface05;
|
||||
/*
|
||||
泛型接口:在接口中定义一个未知的类型
|
||||
泛型接口的格式:
|
||||
public interface 接口名<T> {
|
||||
|
||||
}
|
||||
|
||||
泛型接口的泛型类型何时确定???
|
||||
1.在定义实现子类中直接确定接口的类型
|
||||
2.在实现子类中不确定类型,在创建该实现子类对象时才确定
|
||||
*/
|
||||
public interface MyInterface<T> {
|
||||
|
||||
//泛型作为参数
|
||||
void method1(T t);
|
||||
|
||||
//泛型作为返回值
|
||||
T method2();
|
||||
|
||||
//泛型既作为参数,又作为返回值
|
||||
T method3(T t);//是不是泛型方法?????
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user