7

We currently have one class that won't compile with openjdk 6. The following shortened 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 can't change the signature of the method2:

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

It compiles with oracles java versions and openjdk 7 - but fails with openjdk 6, and, unfortunatly, that's the version that we have to use to compile the (original) code.

The error message is

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 how to change the implementation of method2 so that it would compile. I wouldn't even care about compiler warnings...

2
  • looks like a bug. Eclipse compiler and Sun's compiler don't say anything about this. Apr 3, 2012 at 15:54
  • @GuillaumePolet - a bug or an overly strict handling of generic types of that java version. And, yes, eclipse doesn't complain (which made it quite complicated to reproduce this nasty error that kills the build). Apr 3, 2012 at 16:04

1 Answer 1

11

I would try specifying the bounds explicitly, like this:

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

However, more generally, I don't see the need for the type parameter C at all. None of method's arguments or its return type references C at all, so if you can change the signature of method, I would just omit that type parameter entirely.

1
  • Ah, sorry, this is really a small sample class that simply focusses on the error. The real methods use all type parameters. Apr 3, 2012 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.