You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Guice, we have @Inject fields, which should only be set by the injector when creating the class. Since they can't be marked final, we often prefer to use constructor injection instead, even though it's quite bulky.
Similarly in GWT, fields cannot be marked final because the serialization mechanism needs to be able to set the values in the server when populating a data object.
We should be able to enforce that such fields are never re-assigned in code within the class.
We might want an annotation for this, maybe in JSR305, or maybe JSR330 (which would be nice since other DI frameworks should take advantage). For Guice, you could imagine @Inject(finalish=true) but if we do GWT, may as well make an annotation.
Probably not practical to do this with non-private fields since we'd have to scan outside the enclosing class.
The text was updated successfully, but these errors were encountered:
Would this be problematic for non-reflection-based DI frameworks like Dagger? They generate code which would then be compiled by javac, and if we add a check that fields with a certain annotation should be treated as final, then the generated code would also have to abide by that rule.
I agree with Kevin that this is probably not a high enough priority to get done. Marking WillNotFix, but if you want to work on it please reopen and send us your code.
Original issue created by alexeagle@google.com on 2012-07-30 at 05:15 PM
Suggested by David Mankin:
In Guice, we have @Inject fields, which should only be set by the injector when creating the class. Since they can't be marked final, we often prefer to use constructor injection instead, even though it's quite bulky.
Similarly in GWT, fields cannot be marked final because the serialization mechanism needs to be able to set the values in the server when populating a data object.
We should be able to enforce that such fields are never re-assigned in code within the class.
We might want an annotation for this, maybe in JSR305, or maybe JSR330 (which would be nice since other DI frameworks should take advantage). For Guice, you could imagine @Inject(finalish=true) but if we do GWT, may as well make an annotation.
Probably not practical to do this with non-private fields since we'd have to scan outside the enclosing class.
The text was updated successfully, but these errors were encountered: