ArrayList<Class<?>>
与ArrayList<Object>
相同但不能转换的情况怎么可能?相同的擦除,但不是相同的类型。
我的代码当前在两个eclipse错误之间切换。
GenericExclusiveSelectionPanel transport =
new GenericExclusiveSelectionPanel(StringConstants.TRANSPORT,
(ArrayList<Object>)TransportManager.getInstance().getTransportTypes());
表示:
Cannot cast from ArrayList<Class<Transportable>> to ArrayList<Object>
如果我然而除去演员和创建一个构造函数:
GenericExclusiveSelectionPanel(String, ArrayList<Class<Transportable>>)
我得到的日食错误:
Erasure of method GenericExclusiveSelectionPanel(String,
ArrayList<Class<Transportable>>) is the same as another method in type
GenericExclusiveSelectionPanel
它然后突出构造函数(下)作为冲突的构造函数。
GenericExclusiveSelectionPanel(String title, ArrayList<Object> arrayList)
为什么你会期望一种类型可以被转换为另一种类型,只是因为它们具有相同的擦除? – user2357112
@LawrenceColes请阅读[我应该怎么做当有人回答我的问题](http://stackoverflow.com/help/someone-answers)。是的,很好的问题。从我+1。请看看我的答案,并让我知道你是否需要任何澄清 – CKing