File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes warning [unchecked] unchecked call to add() in ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "warning [unchecked] unchecked call to add() in ArrayList" Watch "warning [unchecked] unchecked call to add() in ArrayList" New topic

warning [unchecked] unchecked call to add() in ArrayList

Graham Cole

Joined: Sep 14, 2005
Posts: 4
I get a warning such as the one in the subject line of this post whenever I call things like .add() or .put() (depending on the type of variable of course). I'm wondering what a "checked" call would look like so that I can ensure the stability of my program and get the compiler to quit warning me about me ramped disregard for checking calls.
marc weber

Joined: Aug 31, 2004
Posts: 11343

The warning is about the "type safety" introduced by generics in Java 1.5. To eliminate the warnings, you can specify the type of object that the ArrayList is supposed to hold -- for example, ArrayList<String>...

[ October 06, 2005: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
As you can see, the method call itself does not change. You need to change the declaration of your ArrayList variable instead. If you want more information about this, google for "Java generics".


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: warning [unchecked] unchecked call to add() in ArrayList
It's not a secret anymore!