Question about generics - the type being deduced does not match the declared boundaries (s)

We currently have one class that will not compile with openjdk 6. The following abbreviated class reproduces this error:

public class Copy implements ICopy { public <A,B extends List<A>,C extends Map<A,B>> A method(A a, B b) { A something = null; return something; } @Override public <A,B extends List<A>> A method2(A a, B b) { return method(a,b); } } 

The interface is simple, it just shows that we cannot change the signature of method2 :

 public interface ICopy { public <A,B extends List<A>> A method2(A a, B b); } 

It compiles with versions of oracles java and openjdk 7 - but does not work with openjdk 6, and, unfortunately, this version, which we must use to compile the (source) code.

Error message

 Copy.java:15: invalid inferred types for C; inferred type does not conform to declared bound(s) inferred: java.util.Map<A,B> bound(s): java.util.Map<A,B> return method(a,b); ^ 

All I need are some ideas on how to change the implementation of method2 so that it method2 . I would not even bother with compiler warnings ...

+6
source share
1 answer

I would try to explicitly specify the boundaries, for example:

 return this.<A,B,Map<A,B>>method(a,b); 

However, in general, I do not see the need for a type C parameter at all. None of the arguments to method or its reference reference type are C , so if you could change the signature of the method , I would just completely omit this type parameter.

+10
source

Source: https://habr.com/ru/post/912327/


All Articles