JavaSE-15.3.4【泛型接口】
1 package day6.lesson3.p4; 2 3 /* 4 3.4 泛型接口 5 6 格式: 7 修饰符 interface 接口名<类型> { } 8 9 */ 10 public class GenericDemo { 11 public static void main(String[] args) { 12 Generic<String> g1 = new GenericImpl<>(); 13 g1.show("tom"); 14 15 Generic<Integer> g2 = new GenericImpl<>(); 16 g2.show(30); 17 } 18 }
1 package day6.lesson3.p4; 2 3 public interface Generic<T> { 4 void show(T t); 5 }
1 package day6.lesson3.p4; 2 3 public class GenericImpl<T> implements Generic<T>{ 4 @Override 5 public void show(T t) { 6 System.out.println(t); 7 } 8 }