Default value annotation?
I was wondering if it would be possible to implement setting default value for a property using an annotation?
It would be a bit cleaner IMO. Something like:
@Value.Immutable
public interface Interface {
@Value.Default("default")
String someString();
}
vs
@Value.Immutable
public interface Interface {
default String someString() {
return "default";
}
}
The annotation processor could probably check that the value passed to the annotation is the same type as the return type?
I understand we're saving a couple of lines here but are there other benefits in having the expression not in the method body ?
BTW @Value.Default("foo" + 33) is also a valid annotation expression.
@asereda-gs I can't think of any other benefits than saving a couple of lines. But one significant difference in behaviour is when using a default annotation, any manual implementations of the interface do not inherit the default value, which may be desired in some circumstances.