The code for copying an array with Object.clone is a bit cumbersome. Once generics are added to the language, it will be possible to do better. The following method could be added to Arrays:
public static <T>[] copy(<T>[] original);
This would make it very easy to copy an array:
Foo[] orig = ... ;
...
Foo[] copy = Arrays.copy(orig); // No cast!
(Internally, the new method would use Object.clone.)
public static <T>[] copy(<T>[] original);
This would make it very easy to copy an array:
Foo[] orig = ... ;
...
Foo[] copy = Arrays.copy(orig); // No cast!
(Internally, the new method would use Object.clone.)
- duplicates
-
JDK-4431115 java.util.Arrays: Add copy methods
-
- Closed
-
-
JDK-4900415 The clone method on arrays should be strongly typed
-
- Resolved
-