Skip to content

Instantly share code, notes, and snippets.

@zaki50
Created August 12, 2011 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaki50/1142068 to your computer and use it in GitHub Desktop.
Save zaki50/1142068 to your computer and use it in GitHub Desktop.
copyOf.java
public static <T> T[] copyOf(T[] orig) {
if (orig == null) {
return null;
}
@SuppressWarnings("unchecked")
T[] newArray = (T[]) Array.newInstance(orig.getClass().getComponentType(), orig.length);
System.arraycopy(orig, 0, newArray, 0, orig.length);
return newArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment