Comment 2 for bug 611284

Revision history for this message
Dmitry (dmitry-korolyov) wrote :

// The following code does not compile under openjdk-6, while it compiles under openjdk-7 and sun-jdk-6

// Error message:
//Test.java:[10,14] invalid inferred types for K,V; inferred type does not conform to declared bound(s)
// inferred: C
// bound(s): java.lang.String

// java -version
// java version "1.6.0_23"
// OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10)
// OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

// uname -srvmpio
// Linux 3.0.0-15-generic #24-Ubuntu SMP Mon Dec 12 15:23:55 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

import javax.annotation.Nullable;
import java.util.Comparator;
import java.util.TreeMap;

public class Test {
  public static void main(String[] args) {
    newTreeMap(String.CASE_INSENSITIVE_ORDER);
  }

  public static <C, K extends C, V> TreeMap<K, V> newTreeMap(
      @Nullable Comparator<C> comparator) {
    // Ideally, the extra type parameter "C" shouldn't be necessary. It is a
    // work-around of a compiler type inference quirk that prevents the
    // following code from being compiled:
    // Comparator<Class<?>> comparator = null;
    // Map<Class<? extends Throwable>, String> map = newTreeMap(comparator);
    return new TreeMap<K, V>(comparator);
  }
}