Reducing verbosity for generics
Johannes Spangenberg
johannes.spangenberg at hotmail.de
Mon Jun 10 21:05:03 UTC 2024
> and any implementation of withFoo() would just have to return an
> object with type compatible with Builder<T>.
With these rules, the compiler would allow the following code, although
it is broken:
public class Builder { // May have sub-types
...
this.class copy() {
return new Builder(this);
}
...
}
Anyway, there are probably solutions to make it work in most situations
using more elaborate rules for the type system. I guess you could also
argue that it is OK that the compiler cannot detect the broken code
above, and the application should just throw a ClassCastException. After
all, it wouldn't be the only case where broken code is not detect at
compile time. However, I think such change would require careful
consideration of different solutions to the problem (and whether the
problem justifies special syntax and rules).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240610/4e807fb5/attachment-0001.htm>
More information about the amber-dev
mailing list