我很難用google搜索這個。我發現了很多文章,但我仍然無法解決我的問題。java - 鑄造泛型
這裏是我的代碼:
List<MyMainClass> mySource = (List<MyMainClass>) session.getAttribute("myAttribute");
的session.getAttribute( 「myAttribute」)可能返回List<MyObject1>
或List<MyObject2>
。無論MyObject1
和MyObject2
是MyMainClass
子現在我有2種功能。第一個接受List<MyObject1>
,另一個接受List<MyObject2>
。現在即時得到月食
The method myMethod1(List<MyObject1>) in the type MyAction is not applicable for the arguments (List<MyMainClass>)
你可以添加其中'myMethod1'定義代碼,以及如何正在調用它?看起來'myMethod1'需要一個'MyObject1'列表,但是你傳遞一個MyMainClass'列表,這個列表不會被接受。 –