I have a variable that must meet two conditions, and I want to set them in the definition
I know that I can define either condition with an individual variable, like
You can declare type parameters that have multiple bounds, such as:
public static void test(Class clazz)
But you cannot declare a variable that has multiple bounds:
private Class extends A & B> variable; // doesn't work
You can create an abstract
class C
that extends A
and implements B
, so that only one bound is required.
abstract class C extends A implements B {}
Then:
private Class extends C> variable;