I want to annotate some of the fields of a given bean class with the following annotation:
@Target({FIELD})
@Retention(RUNTIME)
public @interface Process {
Class<? extends ProcessingStrategy> using() default DefaultImplStrategy.class;
}
Without going into the domain too much, each annotated property needs to have a ProcessingStrategy defined on it, hence the using() property on the annotation. That's fine and works the way I'd like it to.
I also want to specify a default implementation of the strategy, to be used most of the time (the default defined below). This works fine in Eclipse.
However, when I try to compile this using a regular JDK (invoked through maven) I get the following error:
found : java.lang.Class<DefaultImplStrategy>
required: java.lang.Class<? extends ProcessingStrategy>
I'm guessing it's some combination of generics, annotations, class literals and defaulting that are at fault here but I honestly do not know why. I've had a look at the rules around default values in the JLS and I don't seem to be violating anything.
Given that DefaultImplStrategy definitely implements ProcessingStrategy, what am I doing wrong here?
To set a default value for primitive types such as boolean and int, we use the literal value: @Value("${some. key:true}") private boolean booleanWithDefaultValue; @Value("${some.
The @interface element is used to declare an annotation.
We can also explicitly specify the attributes in a @Test annotation. Test attributes are the test specific, and they are specified at the right next to the @Test annotation.
The short version of this is that some combination of maven, Lombok and default annotations don't play nicely together. The longer version is on the Lombok mailing list.
The solution is relatively simple: fully qualify the default Type i.e.
@Target({FIELD})
@Retention(RUNTIME)
public @interface Process {
Class<? extends ProcessingStrategy> using() default com.example.processing.DefaultImplStrategy.class;
}
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