How do I clear up this ambiguous call to Arrays.copyof()?

I’m running AIDE on my Android phone, and am having trouble compiling the following bit of Java code:

elements = Arrays.copyOf(elements, elements.length * 2);

  • Is it crucial for performance to have ViewHolder as static in a ViewHolder pattern?
  • InputMethodManager holds reference to the tabhost - Memory Leak - OOM Error
  • Saving and restoring view state android
  • How to change a layer-list drawable?
  • Does Google Cloud Messaging (GCM) work with Kindle Fire?
  • Show all items in AutocompleteTextView without writing text
  • Here elements is of type int[]. The error I’m getting from AIDE is

    Several methods are applicable to (int[], int): 'java.util.Arrays.copyOf(int[], int)' and 'java.util.Arrays.copyOf<T>(T[], int)'

    I would’ve expected the compiler to pick the former option, but it doesn’t. How can I resolve this?

  • What's the difference between activity and intent in Android?
  • AlarmManager does not always execute BroadcastReceiver
  • Unable to start activity ComponentInfo{…}: java.lang.NullPointerException
  • How to obtain AssetManager without reference to Context?
  • Eclipse/Java - Values in R.string.* return int?
  • What's the right way to extend EditText to give it additional “default” functionality
  • One Solution collect form web for “How do I clear up this ambiguous call to Arrays.copyof()?”

    This is a compiler/IDE problem. However, Arrays.copyOf is a quite trivial function, so simply write your own version of it if the problem can’t be fixed with IDE/compiler updates. Another way would be to use reflection to call it. But it comes with some runtime overhead and also makes the code look awkward, so I suggest implementing your own version.

    Here is the code:

    public static int[] copyOf(int[] original, int newLength) {
        int[] copy = new int[newLength];
        System.arraycopy(original, 0, copy, 0,
                         Math.min(original.length, newLength));
        return copy;

    Of course, if you then get the same problem for System.arraycopy, then this does not work. Simply try it. If it does not work, you can place it in a helper class and use a non-buggy compiler to compile this helper class.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.