Compilation error with JDK8 and Guava
Olivier Bourgain
obourgain at gmail.com
Mon Apr 1 23:50:46 PDT 2013
Hi all,
I tried to compile my project at work with the JDK 8 and I get a
compilation error.
The simplest example which I was able to extract is the following. It uses
Guava 1.14.0.1.
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Lists;
public class TestCase {
public static <K, V> Map<K, V> reverseMap(List<Map.Entry<K, V>> list) {
return toMap(Lists.reverse(list));
}
public static <K, V> Map<K, V> toMap(List<Map.Entry<K, V>> list) {
Map<K, V> result = new LinkedHashMap<>();
for (Map.Entry<K, V> entry : list)
result.put(entry.getKey(), entry.getValue());
return result;
}
}
The compilation error is :
» javac -cp lib/guava-14.0.1.jar src/TestCase.java
src/TestCase.java:9: error: method toMap in class TestCase cannot be
applied to given types;
return toMap(Lists.reverse(list));
^
required: List<Entry<K#1,V#1>>
found: List<Entry<K#2,V#2>>
reason: inferred type does not conform to equality constraint(s)
inferred: Entry<Object,Object>
equality constraints(s): Entry<Object,Object>,Entry<K#2,V#2>
where K#1,V#1,K#2,V#2 are type-variables:
K#1 extends Object declared in method
<K#1,V#1>toMap(List<Entry<K#1,V#1>>)
V#1 extends Object declared in method
<K#1,V#1>toMap(List<Entry<K#1,V#1>>)
K#2 extends Object declared in method
<K#2,V#2>reverseMap(List<Entry<K#2,V#2>>)
V#2 extends Object declared in method
<K#2,V#2>reverseMap(List<Entry<K#2,V#2>>)
1 error
The java version is :
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b82)
Java HotSpot(TM) Server VM (build 25.0-b23, mixed mode)
The same code compiles without error with Java 1.7.
Olivier Bourgain
More information about the lambda-dev
mailing list