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
I see code like Optional<String> something = const Optional<String>.absent();. This allocates a new empty optional per type, even though they all behave the same.
Have you considered using a single Optional<Null> for all absent optionals?
Even if you can't change the API at this point, you could still make the above allocate an Optional<Null> instead by writing the constructor as:
Since Optional<Null> is a subtype of any other Optional<X>, you get to reuse the same const instance in all the places it's created without type issues.
The text was updated successfully, but these errors were encountered:
I see code like
Optional<String> something = const Optional<String>.absent();
. This allocates a new empty optional per type, even though they all behave the same.Have you considered using a single
Optional<Null>
for all absent optionals?Even if you can't change the API at this point, you could still make the above allocate an
Optional<Null>
instead by writing the constructor as:(A little hack-ish, but it should work :).
Since
Optional<Null>
is a subtype of any otherOptional<X>
, you get to reuse the same const instance in all the places it's created without type issues.The text was updated successfully, but these errors were encountered: