Extending 15.28 to include toString() on an enum constant

John Rose john.r.rose at oracle.com
Tue Jul 10 00:19:40 UTC 2018

On Jul 9, 2018, at 6:10 AM, Brian Goetz <Brian.Goetz at Oracle.COM> wrote:
> Virtual methods are much riskier to constant fold than static ones (in part, because it's action-at-a-distance; a declaration modifier on a supertype causes folding of a method in a subtype.)

As a halfway point between general virtuals and statics,
virtuals in final classes or sealed hierarchies are more
like statics than not.  The risk of action at a distance is
that the class would be de-finalized or the hierarchy
would be un-sealed, thus turning the virtual API point
into a dynamically resolved method.

Maybe enums could live in the halfway point, since they
are final and/or sealed.

A second problem with virtuals relative to statics is they
are dependent on the receiver type, so for sealed (not final)
classes, the static compiler might not be able to decide
on the concrete type of an operand.  That can be special
cased for enums also.

enum Foo {  // Foo is sealed; Foo$Bat is final
  Bar, Baz, Bat { 
    public String toString() { return "Bat, actually"; } };
  public String toString() { return "a Foo"; }

— John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20180709/c98d4f08/attachment-0001.html>

More information about the amber-spec-experts mailing list