答案可能很无聊:出现警告时,它不是类型安全的.而已.
在此示例中可以看到为什么它不是类型安全的:
import java.util.HashMap;
import java.util.Map;
class SomeType {}
class SomeSubType extends SomeType {}
class SomeOtherType {}
public class CastWarning
{
public static void main(String[] args)
{
Map originalMap = new HashMap();
Map extends SomeType, SomeOtherType> map = originalMap;
Map castedMap = (Map) map;
// Valid because of the cast: The information that the
// key of the map is not "SomeType" but "SomeSubType"
// has been cast away...
SomeType someType = new SomeType();
SomeOtherType someOtherType = new SomeOtherType();
castedMap.put(someType, someOtherType);
// Valid for itself, but causes a ClassCastException
// due to the unchecked cast of the map
SomeSubType someSubType = originalMap.keySet().iterator().next();
}
}