1.Student泛型类 package s0222泛型类; //使用时确定类型,比如以下这个例子中,学生的成绩的类型组合可以是多种多样的 public class Student { private T1 javaScore; private T2 oracleScore; public Student() { } public Student(T1 javaScore, T2 oracleScore) { this.javaScore = javaScore; this.oracleScore = oracleScore; } public T1 getJavaScore() { return javaScore; } public void setJavaScore(T1 javaScore) { this.javaScore = javaScore; } public T2 getOracleScore() { return oracleScore; } public void setOracleScore(T2 oracleScore) { this.oracleScore = oracleScore; } @Override public String toString() { return "Student [javaScore=" + javaScore + ", oracleScore=" + oracleScore + "]"; } } 2.测试类 package s0222泛型类; public class Test { public static void main(String [] args) { Student stu1=new Student("17",3); //成绩类型是String 和Integer System.out.println(stu1.toString()); Student stu2=new Student(1,3.2); //成绩类型是Integer和Double System.out.println(stu2.toString()); } }