Skip to content

Tag Archives: java

cloning woes

The implementation of Object.clone() prevents guaranteed type-safe (both compile- and runtime) code from compiling. The following class will not compile: public class SafeCloner { public Object cloneOrNull(Cloneable in) { try { return in.clone(); } catch(CloneNotSupportedException) { return null; } } } (Yes I know that strictly speaking this isn’t type-safe. That’s what this article is [...]