62,623
社区成员
发帖
与我相关
我的任务
分享public class Test {
public static void main(String[] args) {
Test.<MyInteger> test();
}
public static <T extends Comparable<T>> void test() {
T[] result = (T[]) new MyInteger[10];
result[0] = (T) new MyInteger(1);
System.out.println(((MyInteger) result[0]).getValue());
}
}
class MyInteger implements Comparable{
int value;
MyInteger(int value){
this.value = value;
}
public void setValue(int value){
this.value = value;
}
public int getValue(){
return value;
}
public int compareTo(Object o) {
// TODO Auto-generated method stub
return 0;
}
}public class Test {
public static void main(String[] args) {
Test.<String> test();
}
public static <T extends Comparable<T>> void test() {
T[] result = (T[]) new String[10];
result[0] = (T) new String("1");
System.out.println(result[0]);
}
}