kostaskougios / cloning

deep clone java objects
Other
591 stars 112 forks source link

Fix for a ClassCastException #101

Closed tweimer closed 4 years ago

tweimer commented 4 years ago

This commit fixes a ClassCastException in that method.

See the contract of Collection.toArray(): "The returned array's runtime component type is Object." That is because of the type erasure.

Thus casting Object[] to Class[] will result in ClassCastException.

java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class [Ljava.lang.Class; ([Ljava.lang.Object; and [Ljava.lang.Class; are in module java.base of loader 'bootstrap') at com.rits.cloning.Cloner.setExtraStaticFields(Cloner.java:224)