Re: What's wrong with this sentence?
- From: cool_guy <venkatesh.jk@xxxxxxxxx>
- Date: Wed, 31 Oct 2007 02:07:15 -0700
The intention behind using generics is to avoid surprises for the JVM.
i.e., You should use generics to avoid runtime(class cast) exceptions.
So in this case you are ought to get this warning in eclipse. There is
nothing wrong in type casting as well, as you are sure that the
attribute you are getting is what you have set before. Well, you can
avoid this warning by implementing Map interface and having something
like this:-
class ItemInfoMap extends HashMap<String,ItemInfo> implements
Map<String,ItemInfo>{
public ItemInfoMap put(String key, ItemInfo value) {
return super.put(key, value);
}
public ItemInfoMap get(String key) {
return super.get(key, value);
}
}
Now Use ItemInfoMap instead of Map :-)
ItemInfoMap userCart = (ItemInfoMap)
session.getAttribute("userCart");
Hope this helps!
Thanks!
On Oct 31, 1:17 pm, "JTL.zheng" <jtl.zh...@xxxxxxxxx> wrote:
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.
.
- Follow-Ups:
- Re: What's wrong with this sentence?
- From: Lew
- Re: What's wrong with this sentence?
- References:
- What's wrong with this sentence?
- From: JTL.zheng
- What's wrong with this sentence?
- Prev by Date: Re: Why are women too dumb to program a computer???
- Next by Date: Re: Why are women too dumb to program a computer???
- Previous by thread: What's wrong with this sentence?
- Next by thread: Re: What's wrong with this sentence?
- Index(es):
Relevant Pages
|
|