This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I'm afraid that's not possible. lst is a List object. So it cannot be assigned to a String reference variable. It will result in a compiler error. Object is the super-type of all types in Java, so it can be assigned to a Object reference variable.
May be I have mis-understood your reply. Can you please explain ?
P.S. : As I have stated, the code I have posted is not exactly where I faced this problem. It's a simplified version of it. I faced this issue when I was retrieving an attribute from a Request object in a Servlet. request.getAttribute() always returns the object as an Object.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Will Sun do anything regarding this in a future compiler? It looks really bad when I put @SuppressWarnings in the code.
No, because it's your code that's the problem and not the compiler. You are doing something dangerous and it's being helpful by giving you a warning. Generics provide type safety and you are circumventing that type safety here. This will NEVER change.
Be thankful you have @SuppressWarnings to let the code reader know that you know what you are doing and the warning can be safely ignored.