aspose file tools*
The moose likes Beginning Java and the fly likes Problem getting ArrayList from servlet context attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem getting ArrayList from servlet context attribute" Watch "Problem getting ArrayList from servlet context attribute" New topic
Author

Problem getting ArrayList from servlet context attribute

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
I'm getting this compile warning...
warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.ArrayList
...when from line 2 of this code...


I've tried...

...and various other, messier, alternatives but can not get a clean solution.

Can anyone help?

Thanks,
James
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Have you tried this?.


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

Because neither the compiler nor the JVM can guarantee that the object is an ArrayList<HttpSession>, only that it's an ArrayList, you will never get this to work without a warning. So in cases like this you have to suck it up and use @SuppressWarnings("unchecked").


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
OK, thanks to you both.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem getting ArrayList from servlet context attribute