Like Object [] cloneable

Object[] o = new Object[]{}; System.out.println(o instanceof Cloneable); 

This gives true as o / p. I could not understand why?

+4
source share
2 answers

All Java arrays are Cloneable and Serializable.

The clone on the array simply copies the array (shallow copy, not cloning of the content).

+10
source

Array support (shallow) cloning, mostly.

From section 10.7 of the JLS :

All array type members from the following:

  • The public final field length that contains the number of components in the array (the length can be positive or zero).
  • A public, public clone method that overrides a method with the same name in a class object and does not throw exceptions. The clone return type of the array type T [] is T [].
  • All members inherited from the Object class; the only object method that is not inherited is its clone method.

and

Each array implements the Cloneable and java.io.Serializable interfaces.

+4
source

Source: https://habr.com/ru/post/1306669/


All Articles