Currently I am doing
import org.easymock.EasyMock;
...
foo.bar(EasyMock.<List<String>>anyObject());
I wonder if there is a way to avoid mentioning the class EasyMock
. I have something like this in mind:
import static org.easymock.EasyMock.anyObject;
...
foo.bar(anyObject<List<String>>());
which, however, does not compile. Any other way to do it?
There is no way to provide type-arguments to statically imported methods (without including the class name as you do in your first snippet). There's simply no such syntax supporting it.
See Section 15.12, Method Invocation Expressions in the Java Language Specification:
MethodInvocation:
MethodName ( ArgumentListopt )
Primary . NonWildTypeArgumentsopt Identifier (ArgumentListopt)
super . NonWildTypeArgumentsopt Identifier (ArgumentListopt)
ClassName . super . NonWildTypeArgumentsopt Identifier (ArgumentListopt)
TypeName . NonWildTypeArguments Identifier (ArgumentListopt)
The first option is the only one that does not involve a preceding dot, and that one does not include the possibility to provide type arguments (as the other ones do).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With