On Jul 9, 2018, at 6:10 AM, Brian Goetz <brian.go...@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

Reply via email to