What's wrong with this sentence?



Hashtable<String, ItemInfo> userCart = (Hashtable<String, ItemInfo>)
session.getAttribute("userCart");

I am using Eclipse

It get a warning:
Type safety: The cast from Object to Hashtable<String,ItemInfo> is
actually checking against the erased type
Hashtable


Hashtable<String, ItemInfo> userCart = (Hashtable)
session.getAttribute("userCart");

still get a warning too:
Type safety: The expression of type Hashtable needs unchecked
conversion to conform to
Hashtable<String,ItemInfo>

what's wrong with this sentence?
how can I fix it?

Thank you very much in advance.

.



Relevant Pages

  • Re: getAttributes() in javax.xml.stream.events.StartElement
    ... "The expression of type Iterator needs unchecked conversion to ... but it gives me a different "type safety" ... warning complaining about an "unchecked cast from Iterator to ... The root cause of the problem is, that getAttributes returns an untyped Iterator and there is no way to cast this into a typed iterator without getting a warning, as the compiler cannot possibly know what kind of objects this iterator returns. ...
    (comp.lang.java.help)
  • Re: Whats wrong with this sentence?
    ... Type safety: The cast from Object to Hashtableis ... You get the warning, since the runtime will only cast your "session.getAttribute" to Hashtable, and can not verify the contents of the table. ... *could* spuriously throw a ClassCastException (since the cast to ItemInfo is automatically generated by the compiler). ...
    (comp.lang.java.programmer)
  • Re: how to solve this warning in Eclipse?
    ... The basic idea of generics is to introduce several features that encourage type safety in your code. ... Basically, to stop your warnings, you need to tell Java what sort of Object you are going to store in your Vectors. ... No matter what I do I can't get the warning to go away. ...
    (comp.lang.java.programmer)
  • Re: getAttributes() in javax.xml.stream.events.StartElement
    ... "The expression of type Iterator needs unchecked conversion to ... but it gives me a different "type safety" ... warning complaining about an "unchecked cast from Iterator to ... The root cause of the problem is, that getAttributes returns an untyped Iterator and there is no way to cast this into a typed iterator without getting a warning, as the compiler cannot possibly know what kind of objects this iterator returns. ...
    (comp.lang.java.help)
  • How to initialize variable of type Vector[] in Java 5.0?
    ... In Eclipse, the assignment ... gives the warning ... Type safety: The expression of type Vector[] needs unchecked ...
    (comp.lang.java.programmer)