Java基础Demo -- 泛型接口的示例

泛型接口 public interface MyInterface<T>{} 的简单入门示例

/**
* 类实现了一个泛型接口,并扩容下
*/
 
interface AI<T> {
	void sss(T t);
}

class BI<T,K> implements AI<T>{ //类BI<T,K>实现接口AI<T>,扩容出K

	private K k;
	public void setK(K k){
		this.k = k;
	}
	public void sss(T t){
		System.out.println("t is["+t+"], k is["+k+"]");
	}
}


public class MyClsDemo {

	public static void main(String[] args){

		BI<String,Integer> bi = new BI<>();
		bi.setK(100);
		bi.sss("abc");
	}
}

猜你喜欢

转载自blog.csdn.net/mmlz00/article/details/85166819