• Post Reply Bookmark Topic Watch Topic
  • New Topic

Netbeans : unchecked or unsafe operations compiler error  RSS feed

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

With the following code in Netbeans, I compile once and I get the following error


private List<String> removeDuplicates(List<String> list)
{

HashSet hs = new HashSet(list);
List<String> newList = new ArrayList<String>(hs);
return newList;
}

java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

When I press compile again (F9) the message disappears and compile fine



Can anyone hlep me with this please? It's rather annoying not knowing the exact cause..is it my HashSet declaration?

Thanks,


Colm

 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Colm Dickson wrote:
HashSet hs = new HashSet(list);

java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.


error is different and warning is different . Since you use jdk version 1.5 and above . Compiler expect a generic declaration.
the culprit is your HashSet with out generic declaration

Hope this helps
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was a useful reply, yes.

Please use the code button; it makes your code much easier to read.
 
Colm Dickson
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,


I needed something like


instead of



Colm
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!