Use @transient as an alternative for @constructorOnly #13423
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The motivation for the PR is to move away from @constructorOnly to @transient. The documentation for @transient should be like the following:
Why rename?
@constructorOnly
is bulky and awkward to write with its camelCase.transient
is short and to the point. It is also already known, so we generalize the previous meaning instead of inventing a new name.@transient
will be very important once we go to capture checking. Essentially the rule would be that any class parameternot marked as @transient is counted as possibly captured by the class. So we need a short name for this.
But even without the capture checking use case
@transient
is important, since it can be used to statically prevent certain classes of space leaks. So it plays a role similar to@tailrec
.Is the Double Meaning a Problem?
I think not. transient is the opposite of persistent. It marks something to have a shorter lifetime than usual. So for parameters that means it's not persisted as a field of the class and for fields it means it's not persisted when serializing.
If anything the parameter meaning is the more common and natural one, since most people do not care about Java serialization.
Is the Renaming Burdensome?
I hope not. Sor far
constructorOnly
has been documented only directly in the class. A Google search throws up nothing else. The CB has not a single use of it. So I think we can safely introduce @transient and deprecate @constructorOnly. But we should do it quickly.