Deconstructor can not be overriden ? Was: Deconstruction patterns
Brian Goetz
brian.goetz at oracle.com
Wed Mar 8 17:21:13 UTC 2023
> It means that once a deconstructor is provided, subclasses can not change it.
Correct. I don't see this as a problem, or as inconsistent with
inheritance.
> If know that a lot of features introduced since Java 5 does not support inheritance but maybe you should be more public about the fact that inheritance is a second class citizen in Java. Personally, i'm fine with that but i want to be sure it's not an unintended side effect.
Confirmed: that A's dtor is A's exclusively to define is not an
unintended side-effect. "Second class citizen" or "inheritance is dead"
is unhelpful rhetoric, though. This is more like `instanceof` or cast;
B can't override these operators either. B also can't override the
parameterization of A's supertypes, but that doesn't bother us either;
if A extends Foo<A>, we can't make B extends Foo<B>.
>
>> Is there a specific problem here that you are worried about?
> A specific implementation of Map.Entry not being able to fix the default implementation.
Map.Entry has two choices:
- declare a dtor, in which case this is the final word on the subject, or
- declare an abstract instance pattern (perhaps with a default), which
would allow overriding.
The two are different, and will be used in different situations. Part of
the API design is choosing between them. But also, note that the
matcher implementation can only use functionality that is already
present in the interface. This is significant, because:
> By example, if my Map is thread-safe and implemented with two arrays and a lock, i will want the deconstructor to be able to synchronize on the lock, something the default implementation will not do.
Such a Map already has this problem, as Map.Entry already contains
getKey and getValue methods which can be used independently. If they
are allowed to return inconsistent results, it doesn't matter what the
dtor does, since users are free to go to the source and get an
unsynchronized view using getKey/getValue.
More information about the amber-spec-experts
mailing list