Revert Optional<T extends Object> to Optional<T> #667
Merged
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.
Optional is intended as a substitute for non-nullable values. Ideally,
it should have a generic type of
T extends Object
in order to preventnon-sensical declarations like
Optional<Foo?>
. Such declarations areunlikely to happen intentionally, but one could imagine the case of an
Optional used in another generic class, where T is a nullable type.
In #652, we prevented such uses by declaring Optional as
Optional.
This turns out to be a significant breaking change, since previously, T
implicitly extended
dynamic
and therefore checks like the followingdidn't produce any analysis errors:
where
someMethod
is a method defined onT
.A survey of the Google codebase suggests this would be a fairly
extensive breaking change. Given that Optional makes little sense once
null-safety is enabled in the language by default, the simpler change
may simply be to leave as-is and deprecate the class once null-safety
lands in the language.
It appears that there are no checks on the return type of
transform
,and this seems significantly unlikely, therefore we leave that change in
place.
This partially reverts 28301f9.
Related: #666
Related: #606