I am writing a class that needs to be thread safe. Following one of the principles of concurrent programming, I am trying to make my instance variables final where possible.
The problem is that I often cannot use the final keyword due to the use of a DI framework (in this case, Spring). For e.g. any variable that is set in a method with the @PostConstruct
annotation cannot be final. Also, any variable that has an @Value
annotation cannot be final too.
What I was hoping exists is an @EffectivelyFinal
annotation. It is relatively trivial to create one that exists solely for documentation purposes with no functionality. However, I was hoping that a solution already exist where the annotation can fail the compiler if it detects that you are trying to assign a value to the variable after it has been assigned for the first time.
Would anyone know if such a solution exists please?