Records: supertype?

Brian Goetz brian.goetz at oracle.com
Tue Jun 11 21:05:38 UTC 2019


>     We lose out on some future flexibility to add new methods, which
>     might amount to nothing, or might be a big deal.
>
>
> Wouldn't we just introduce the type then once we needed it? It would 
> be awkward, but would it be impossible or inadvisable?

That would not be binary-compatible.

Let's say we had

     record Foo(int x) {}

which was translated without a supertype.  Now we later try to add in 
the supertype, say with a `.toJson()` method, but don't recompile Foo.  
Then:

     Record r = (Record) aFoo;
     String s = r.toJson();

compiles, but throws some form of IncompatibleClassChangeError, since a 
Foo does not extend Record at runtime.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20190611/6a4963eb/attachment.html>


More information about the amber-spec-experts mailing list