wondra
wondra

Reputation: 3583

Java generics multiple arguments with constraints

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?

Upvotes: 1

Views: 74

Answers (1)

Eran
Eran

Reputation: 393986

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.

Upvotes: 3

Related Questions