I use a library that provides an annotation @LibraryAnnotation
with a Boolean parameter parameter
. The default is set to true
by the authors of the library.
Unfortunately, in almost all my use cases, I prefer the annotation with parameter = false
. To achieve the desired behavior, I use @LibraryAnnotation(parameter=false)
instead of @LibraryAnnotation
every time. This is error prone since one easily forgets to set the parameter.
I am wondering if there is a way to simplify things by changing the default value for the parameter of @LibraryAnnotation
or by defining a custom annotation that behaves like @LibraryAnnotation(parameter=false)
, but does not require setting a parameter.
(In this particular case, the library is lombok, but the question could be relevant for parametrized annotations provided by any library. Update: Lombok offers default parameter configuration via a lombok.config
file, but I am still interested in a general solution.)
question from:
https://stackoverflow.com/questions/65857605/changing-java-annotation-parameter-default 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…