Thursday, March 15, 2007

Learned something new today...

I was trying to do a shallow copy rather than a deep copy of a Java HashMap. As far as I can tell, you can't use clone() in Java 5 without getting unchecked cast warnings, period. The solution is to either ignore the warnings, or forgo the shallow copy and instantiate a new version of the object with the old version of the object as an argument (copy instantiation). Generics are cool and suck at the same time...

Reference: http://forum.java.sun.com/thread.jspa?threadID=559703&messageID=2982374

No comments: