Compilation error with JDK8 and Guava
Remi Forax
forax at univ-mlv.fr
Tue Apr 2 02:45:42 PDT 2013
On 04/02/2013 08:50 AM, Olivier Bourgain wrote:
> 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.
Hi Olivier,
could you test with b83 because it looks like a bug that was fixed recently.
cheers,
Rémi
>
> 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