Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5070671

Arrays.binarySearch can't infer int[]

XMLWordPrintable

    • sparc
    • solaris_9

      Name: rmT116609 Date: 07/01/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      SunOS mary 5.9 Generic_112233-12 sun4u sparc SUNW,Sun-Blade-100

      A DESCRIPTION OF THE PROBLEM :
      The method <T> int binarySearch(T[] a, T key, Comparator<? super T> c) in java.util.Arrays doesn't compile if T is an array of a primitive type (int[], long[], etc.)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the program below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The program should compile.
      ACTUAL -
      Foo.java:10: cannot find symbol
      symbol : method binarySearch(int[][],int[],java.util.Comparator<int[]>)
      location: class java.util.Arrays
              Arrays.binarySearch(arr, elem, c);
                    ^
      1 error


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;
      class Foo {
          void foo1() {
              Comparator<int[]> c = new Comparator<int[]>() {
                  public int compare(int[] c1, int[] c2) { return 0; }
              };
              int[][] arr = { { 1 } };
              int[] elem = arr[0];
              Arrays.sort(arr, c);
              Arrays.binarySearch(arr, elem, c);
          }
          void foo2() {
              Comparator<Integer[]> c = new Comparator<Integer[]>() {
                  public int compare(Integer[] c1, Integer[] c2) { return 0; }
              };
              Integer[][] arr = { { 1 } };
              Integer[] elem = arr[0];
              Arrays.sort(arr, c);
              Arrays.binarySearch(arr, elem, c);
          }
      }

      ---------- END SOURCE ----------
      (Incident Review ID: 282110)
      ======================================================================

            ahe Peter Ahe
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: