标签:
public class Test { public static void main(String[] args) { Generics<String> g1 = new Generics<>(); Generics<Integer> g2 = new Generics<>(); Generics<Double> g3 = new Generics<>(); g1.setValue("hello"); g2.setValue(123); g3.setValue(3.14); printGenerics(g2); printGenerics(g3); } private static void printGenerics(Generics<? extends Number> g) { Number number = g.getValue(); System.out.println(number); } }
public class Generics<T> { private T value; public T getValue() { return value; } public void setValue(T value) { this.value = value; } }
标签:
原文地址:http://www.cnblogs.com/fazheng/p/5161705.html