An anonymous class declaration is automatically derived from a class instance creation expression by the Java compiler.
where a class instance creation expression is
ClassInstanceCreationExpression:
new TypeArgumentsopt TypeDeclSpecifier TypeArgumentsOrDiamondopt
( ArgumentListopt ) ClassBodyopt
Primary . new TypeArgumentsopt Identifier TypeArgumentsOrDiamondopt
( ArgumentListopt ) ClassBodyopt
TypeArgumentsOrDiamond:
TypeArguments
<>
ArgumentList:
Expression
ArgumentList , Expression
So, no, the Java language specification does not allow any shortcuts for making your anonymous class implement more interfaces than the type you're sub-typing.
So, to determine the type of the anonymous class
If the class instance creation expression ends in a class body, then the class being instantiated is an anonymous class. Then:
- If T denotes an interface, then an anonymous direct subclass of Object that implements the interface named by T is declared.
[...]
- Let T be the type named by the Identifier and any type arguments. An anonymous direct subclass of the class named by T is declared. The body of the subclass is the ClassBody given in the class instance creation expression.
Your alternative is the way to do it.
You can also use local classes.