1. public class Test {
2. public <T extends Comparable> T findLarger(T x, T y) { //泛型方法
3. if(x.compareTo(y) > 0) {
4. return x;
5. } else {
6. return y;
7. }
8. }
9. }
and:
22. Test t = new Test();
23. // insert code here
Which two will compile without errors when inserted at line 23?
(Choose two.) 2. 这题考察的是泛型方法中参数类型的推断知识 3. Object x = t.findLarger(123, "456");//编译无错 ,123 “456”的最大交集是Object 4. int x =(int) t.findLarger(new Double(123), new Double(456));//编译错误,不能从 Double 强制类型转换为 int 5. int x = t.findLarger(123, new Integer(456));//正常 int 和Integer之间可以拆箱装箱 6. int x = t.findLarger(123, new Double(456));//编译错误,类型不匹配:不能从 Number&Comparable<?> 转换为 int 7. 具体可看张老师的ppt截图 |