1

I was able to find how to declare generics with single argument and multiple constrains and generics with multiple arguments, but strangely enough, not a generic with multiple argument and constraints:

public class Page<U, T implements IPaginableBy<U>> extends ArrayList<T> { }

gives me syntax error after T: "java: > expected". Is it not possible to constrain a an argument on generic type more than one argument?

1 Answer 1

3

Change

public class Page<U, T implements IPaginableBy<U>> extends ArrayList<T> { }

to

public class Page<U, T extends IPaginableBy<U>> extends ArrayList<T> { }

Constrained type arguments always use the extends keyword.

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

1 Comment

Accepting this answer when it allows me (10 mins). Sorry, this was a dumb syntax error - this (redundant?) differentiation between extends and implements is a bit confusing.

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.