0

I have the following classes:

public interface ServiceSynchronizableEntity {
    ....
}

public class BaseListResponse<T> {
    ....
}

public class BaseSynchronizableListResponse<T extends ServiceSynchronizableEntity> extends BaseListResponse<T> {
    ....
}

public class MySecondClass implements ServiceSynchronizableEntity {
    ....
}

public class MyFirstClass extends BaseSynchronizableListResponse<MySecondClass> {
    ....
}

public class What<S extends BaseSynchronizableListResponse<ServiceSynchronizableEntity>> {

}

Then I use it as:

What what = new What<MyFirstClass>();

When I want to use MyFirstClass as a type parameter which extend BaseListResponse<ServiceSynchronizableEntity>> it shows me

Main.java:26: error: type argument MyFirstClass is not within bounds of type-variable S
    What what = new What<MyFirstClass>();
                         ^
where S is a type-variable: S extends BaseSynchronizableListResponse<ServiceSynchronizableEntity> declared in class What

What is wrong?

Edit: One class was missing. Look at: http://ideone.com/D4snKP

Thanks!

4
  • 1
    Works here: ideone.com/gLlG3b. Commented Oct 14, 2014 at 19:44
  • Worked for me too. You got more code to show us what you're doing? Commented Oct 14, 2014 at 19:50
  • Works fine i just tested Commented Oct 14, 2014 at 19:50
  • Please look at the edit. Commented Oct 14, 2014 at 20:10

1 Answer 1

1

The solution I previously posted (now deleted) was similar in that it required a change to the generic signature.

The important change is going from:

class What<S extends BaseSynchronizableListResponse<ServiceSynchronizableEntity>> {}

to:

class What<S extends BaseSynchronizableListResponse<? extends ServiceSynchronizableEntity>> {}

See http://ideone.com/wyXvcl for the fixed version

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.