क्या कोई बता सकता है कि वाई असाइनमेंट लाइन पर एक अवांछित रूपांतरण चेतावनी क्यों है? ध्यान दें कि एक्स या जेड असाइनमेंट पर कोई चेतावनी नहीं है।अप्रत्याशित अनचेक रूपांतरण चेतावनी
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);
}
}
आपकी इकाई, 'बी', 'ए' से कास्ट के बाद untyped है, इसलिए जब आप इसे वापस b.typed (Integer.class) 'के साथ परिवर्तित करते हैं तो यह अनचाहे है।सामान्य प्रकार वर्ग प्रकार के विपरीत हैं; जब वे "निराश" होते हैं तो उन्हें बनाए रखा नहीं जाता है। – Vulcan