Java
Java Basic (5) - Object, clone(), copy
Kate Choi
2021. 5. 19. 01:12
Object
- every type except double, float, long, int, short, byte, char, or boolean is an Object
- includes String, all arrays, your own classes, any pre=supplied classes like Scanner or ArrayList
- these types store a reference to an object, never the object itself
Clone
- Needed to make a completely new object, identical to an existing one
- Gives two independent objects (not shallow copy) -> a change to one will not affect the other
Cloning Arrays
or use shortcut
Cloning Array of Object
- Use .clone() (deepcopy)