• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Generics when trying to use For / In  RSS feed

 
James Dekker
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

I am using JDK 1.5 on Eclipse 3.2.

Basically, I tried to replace:



With:



Here's the original code:



My refactored version:



Eclipse has a warning (in its Problems view) which states:

"Type safety: The expression of type Set needs unchecked conversion to conform to Set<Attribute>"

for this line in the refactored version:



When I run my build script (invoking the javac on these source files and placing them in a standard build dir), this is the second warning message I receive in Eclipse's Console view:


Note: MySampleApp.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.


What am I doing wrong? Am I just supposed to set up Eclipse to ignore these type of warnings (seeing tha the javac also gave me one during compilation, that this is evidenty a problem).

Thanks again!

JD
[ December 21, 2006: Message edited by: James Dekker ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,

I don't know what kind of object "user" is, but if it's something you can change, the issue is that get() is returning a Set rather than a Set<Attribute>. If you can change that get() method, that will make the warning go away.
 
James Dekker
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Mr. Friedman-Hill:

Thank you very much!

I knew it had something to do with the way the get() was being called from user but your explanation cleared up my confusion!

The user's class is not viewable by me as its already been jarred up and placed into Eclipse's build path.

I'll see what I can do to alleviate that situation...

Respectfully,

-James
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!