[英]Java: Warning: References to generic type should be parameterized
currentProfile.getFriends()
方法通過ArrayList返回Iterator。 它按預期工作,但編譯器在將其分配給另一個迭代器時給我一個友好的警告: iterator is a raw type. References to generic type Iterator <E> should be parameterized
iterator is a raw type. References to generic type Iterator <E> should be parameterized
我很少或根本不知道這意味着什么,關心開導我? 如果我的描述不夠清楚,這就是我正在做的事情Iterator friendList = currentProfile.getFriends();
如果可以,請查看方法getFriends()的簽名。 那應該是這樣的
public Iterator<some type> getFriends()
這是您需要在Iterator參考中輸入的類型。 例如,如果方法是:
public Iterator<Friend> getFriends()
采用:
Iterator<Friend> friendList = currentProfile.getFriends();
`Java: Warning: References to generic type should be parameterized`
這意味着您將一個對象的泛型類型設置為一個沒有聲明泛型類型的引用。
例:
List<String> list = new ArrayList<String>();
Iterator itr= list.iterator(); // you'd get that warning on this line, as you are not making iterator a generic type.
it'd disappear when you do this
Iterator<String> itr = list.iterator();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.