RSS feed [root] /weblog /features /java




login:

password:

title search:




 


Mon Jan 06 08:30:32 GMT 2014

generics



As Java still need to support Collection.get(Object) , it is easy to get NPE if you use wrong type accidentally
http://jroller.com/page/sstirling?entry=map_get_object_and_java
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 - http://www.pankaj-k.net/archives/2006/11/how_hard_is_tes.html , 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: http://jroller.com/page/dhall?entry=exploring_the_limits_of_java

Some cool feature, apply generic in comparable - http://tech.puredanger.com/2006/11/22/comparator-jdk5/

Wildcast in generic -http://javarevisited.blogspot.com[..]-is-bounded-and-unbounded-wildcards.html

http://javarevisited.blogspot.com.au[..]trized-class-method-Generic-example.html

http://mydailyjava.blogspot.com.au[..]6/advanced-java-generics-retreiving.html


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