RSS feed [root] /weblog /features /java



title search:


Mon Jan 06 08:30:32 GMT 2014


As Java still need to support Collection.get(Object) , it is easy to get NPE if you use wrong type accidentally
I met this problem when using wicket, one cool feature of ListMultipleChoice is that if the list I press into the constructor is not List, it will persist the type information.
However, if you use this API carelessly and think the List return from the HTML form is always List . Then you will get strangle null pointer exception when you operate with the list instead of ClassCastException, as java will surpress the ClassCastException from ArrayList.get(i) sliencely and just return null to caller.

A related one but not really related to generics - , look like the behaviours difference of primittive and wrapper class at NULL is very easy to get hard to check bug

Another one, JDK generic try to cast to wrong class internally:

Some cool feature, apply generic in comparable -

Wildcast in generic -[..]-is-bounded-and-unbounded-wildcards.html[..]trized-class-method-Generic-example.html[..]6/advanced-java-generics-retreiving.html

(google search) (amazon search)
download zip of files only