A Java geek
  • Me
  • Books
  • Speaking
  • Mentions
  • Focus
  • Newsletters

cloneable

A collection of 1 posts
Cloneable, a Java design gotcha
Java

Cloneable, a Java design gotcha

Some time ago, I described a couple of surprising design choices in the JDK functional interfaces API. Lately, during a lesson, a student of mine proposed to shallow-copy an ArrayList by using the clone() method: I thought this is another API gotcha worth writing about. Cloning an object means a new object is created with the same state as the original one. As per the JavaDoc: Creates and returns a copy of this object. The precise meaning of 'copy' may depend on the class of the object.

Oct 14, 2018
A Java geek © 2008-2026
v. 1e36702bdd5aadacde73bd395fb1b580e1d1f65d/13988790172
Latest Posts