Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Warning: References to generic type should be parameterized

Tags:

java

iterator

currentProfile.getFriends() method returns a Iterator over a ArrayList. It works as supposed but the compiler gives me a friendly warning when assigning it to another iterator: iterator is a raw type. References to generic type Iterator <E> should be parameterized

I have little or no idea what this means, care to enlighten me? if my description were not clear enough, this is what I am doing Iterator friendList = currentProfile.getFriends();

like image 444
Tom Lilletveit Avatar asked Nov 01 '12 00:11

Tom Lilletveit


2 Answers

Please looks at the signature of the method getFriends() if you can. That should look like

public Iterator<some type> getFriends()

the is the type you need to put in the Iterator reference. For example if the method is:

public Iterator<Friend> getFriends()

use:

Iterator<Friend> friendList = currentProfile.getFriends(); 
like image 163
IllegalArgumentException Avatar answered Nov 09 '22 05:11

IllegalArgumentException


`Java: Warning: References to generic type should be parameterized` 

what it means is you are assigning an object with the generic type set to a reference which has no generic type declared.

Example:

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();
like image 5
PermGenError Avatar answered Nov 09 '22 06:11

PermGenError