Java泛型的转换为啥会被提示类型不安全?
classDemo<T,SextendsT>{publicvoidshow(Tt,Ss){t=s;s=(S)t;//为什么这里Eclipse提示Typesafety:Un...
class Demo<T, S extends T>{
public void show(T t, S s){
t = s;
s = (S)t; //为什么这里Eclipse提示Type safety: Unchecked cast from T to S
}
}
package cn.ifavor.app;
public class Program {
public static void main(String[] args){
Student s = (Student)new Object(); //而这里却没有类型安全提示
}
}
class Student{}
这是为什么 展开
public void show(T t, S s){
t = s;
s = (S)t; //为什么这里Eclipse提示Type safety: Unchecked cast from T to S
}
}
package cn.ifavor.app;
public class Program {
public static void main(String[] args){
Student s = (Student)new Object(); //而这里却没有类型安全提示
}
}
class Student{}
这是为什么 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询