posted 10 years ago
A shallow copy of the List<Integer> passed to the constructor will do, because Integer objects are immutable.
The most convenient way to do that is to use the ArrayList constructor that accepts a Collection, as you have in the first example, which will create a new instance of ArrayList that references the same Integer objects in the same order. The second solution that uses the clone() implementation of ArrayList will accomplish the same thing, but the catch is you have to be sure it's an ArrayList before you cast it as such. The third solution, however, will not. It will simply cause vertexIndices to reference the same List instance which could be manipulated directly using the reference passed to the Face class' constructor, which is something you'll definitely want to avoid, and is infact the reason you'd want to perform a shallow copy. By the way, the counterpart to a shallow copy is a deep copy, which in this example wouldn't just create a new ArrayList that references the same Integer objects, but it would create new and equivalent Integer objects as well.
Edit: ack, too late.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.