openjdk team mailing list archive
-
openjdk team
-
Mailing list archive
-
Message #07013
[Bug 611284] Re: OpenJDK compiler 6b20pre on Maverick doesn't recognize Generics Correctly
// 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);
}
}
--
You received this bug notification because you are a member of OpenJDK,
which is subscribed to openjdk-6 in Ubuntu.
https://bugs.launchpad.net/bugs/611284
Title:
OpenJDK compiler 6b20pre on Maverick doesn't recognize Generics
Correctly
Status in “openjdk-6” package in Ubuntu:
Confirmed
Bug description:
OpenJDK compiler can't unify custom type defined in signature by
generics.
Example:
import java.util.List;
public class GenericBug {
public <X extends String, Y extends List<X>, Z extends List<X>> Z add(X element, Y list){
list.add(element);
return list;
}
}
This code compile correctly on Sun JDK but OpenJDK compiler displays error:
"incompatible types
required: Z
found: Y"
But btw Z and Y is the same type: List<X>
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/openjdk-6/+bug/611284/+subscriptions
References