Bound mismatch problem with generics

I have a problem with last method call:


class Y <T extends Z>{
    Z foo() {
             return null;
    }
}
class Z { }
public class HelloWorld {
    public <
             M extends Y<T>,
             T extends Z
    >
    M mp(T template_mp_type, boolean v) {
             return null;
}
    
    @SuppressWarnings("unchecked")
	public <
             M extends Y<T>,
             T extends Z
    >
    M mp(M template_mp, boolean v) {
             return mp(template_mp.foo(), v); // bound mismatch
    }
}

If you change class ‘Y’ to return T instead of Z it will compile. is that what you need?

class Y <T extends Z>{
    T foo() {
             return null;
    }
}

also rename your classes to something besides single letters… by convention these are generic types and it can be really confusing!

Sorry for single name classes, I just wanted to generalize problem. I know if I make some changes in code that it will compile and work, my problem is why it doesn’t work now? I wonder is this a problem with eclipse jdt compiler or it is a problem in my code and it can’t be compiled. I also tried to use openJDK 1.6.0 build 9 on centOS and it failed to compile.

if you change

    return mp(template_mp.foo(), v); // bound mismatch

to

        Z foo = template_mp.foo();
        return mp(foo, v); // bound mismatch

I think it complains because foo is not of type T.

You have an unused parameter T in your Y class… is this intentional?

First of all, thank you very much jurn. Now I think that your last post explains everything and that code is not valid. And yes, parameter T is unused intentional, this is some test code for a features in Java so I played with variety of combination of code examples with parameter types.