y 할당 라인에 유형이 지정되지 않은 경고가있는 이유를 누구나 설명 할 수 있습니까? x 또는 z 지정에 대한 경고는 없습니다.예기치 않은 확인되지 않은 전환 경고
public class Entity<T>
{
@SuppressWarnings("unchecked")
public <TX> Entity<TX> typed(Class<TX> type)
{
return (Entity<TX>) this;
}
@SuppressWarnings("unchecked")
public static <TX> Entity<TX> typed(Entity<?> entity, Class<TX> type)
{
return (Entity<TX>) entity;
}
public static void main(final String[] args)
{
final Entity<?> a = new Entity<Integer>();
final Entity b = (Entity) a;
final Entity<Integer> x = a.typed(Integer.class);
final Entity<Integer> y = b.typed(Integer.class);
final Entity<Integer> z = typed(b, Integer.class);
}
}
엔티티'b'는'a'의 형변환 이후에 타입이 없으므로'b.typed (Integer.class) '로 다시 변환 할 때 타입이 없습니다.일반 유형은 클래스 유형과 다릅니다. 그들은 "다운 캐스팅 (downcasted)"될 때 유지되지 않습니다. – Vulcan