In the official document, you can see this sentence about field injection.
Avoid using field injection with final fields, which has weak semantics.
Why doesn't field injection with final modifier have meanings? Could anyone explain?
In the official document, you can see this sentence about field injection.
Avoid using field injection with final fields, which has weak semantics.
Why doesn't field injection with final modifier have meanings? Could anyone explain?
You are essentially asking the following: what does "weak semantics" mean?
In general, as you have noted, "semantics" is "meaning". Furthermore, in programming semantics refers to:
the rigorous...study of the meaning of programming languages.
When we say "injecting final fields has weak semantics" it means that "injecting final fields makes it difficult to reason rigorously about the meaning of your program."
Why? As noted in the comment by Boris the Spider, "weak semantics" refers to this behaviour:
Use [of setting a final field using reflection] in any other context [than serialization] may have unpredictable effects, including cases in which other parts of a program continue to use the original value of this field"
It means that if you use reflection to set a final
field, the meaning (semantics) of your program becomes obscure because it now has unpredictable behaviour.
The unpredictable behaviour is just that mentioned in the linked docs: other parts of the program can continue to use the original value of the final
field. It becomes unclear which parts of the program are using the original value and which parts are using the reassigned value.