aspose file tools
The moose likes Java in General and the fly likes Warnings with Collections API Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Warnings with Collections API" Watch "Warnings with Collections API" New topic
Author

Warnings with Collections API

Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Hello All,
Pls. consider the following code:


I get a warning when i compile tgis code snippet. I compiled it with -Xlint:unchecked, and I get to see the following warning:

[unchecked] unchecked call to add(E) as a member of the raw type java.util.List

What does this mean? How can i remove the warning?

Any help shall be highly appreciated.

Thanks,
Reema
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24054
    
  13

Java 5 introduced "generics", which provides a way to make collections that are "typesafe". You can read about it here.

Short answer: this code

List<String> titles=new ArrayList<String>();
titles.add("A");

will not give the warning. Read the document linked to above to start to learn why.


[Jess in Action][AskingGoodQuestions]
Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Thanks for the post!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Warnings with Collections API
 
Similar Threads
Array problem
I am close to submit - eliminate a warning message
Compile warning??
Problems with Compiling Generics.
How to cast an Object to a HashMap with out getting unchecked cast warning