Having to delete a sealed interface and start from scratch to add additional implementers, feels unintuitive

Lingo Coder plugins at lingocoder.com
Fri Aug 7 23:14:57 UTC 2020


I apologize if this is the wrong place to discuss a Sealed
Interface/Records
issue in JShell.

The issue is: The only way to update a previously-created sealed
interface 
in JShell, to add new/forgotten records to its permits list, is to first

/drop the original interface, then declare the additional permitted
record(s),
then recreate the sealed interface from scratch; including the
additional 
implementing record(s) in the permits clause of the recreated sealed
interface.

Steps to Reproduce

1. Launch jshell --enable-preview

2. Create a sealed interface

jshell> sealed interface Animal permits Cat, Dog { String breed(); }
|  created interface Animal, however, it cannot be referenced until
class Cat,
   and class Dog are declared


3. Create the two records that you just declared to implement the sealed
interface:

jshell> record Cat(String breed, String name) implements Animal{}

jshell> record Dog(String breed, String name, boolean bites) implements
Animal{}

The interface and two records now exist:

jshell> /types
|    interface Animal
|    record Cat
|    record Dog


5. Now /edit the interface to permit a third record:

/edit Animal

   sealed interface Animal permits Cat, Dog, Fish { String breed(); }

|  Error:
|  cannot find symbol
|    symbol:   class Fish
|  sealed interface Animal permits Cat, Dog, Fish { String breed();}
|                                            ^--^
|  Error:
|  invalid permits clause
|    (illegal reference to supertype Fish)
|  sealed interface Animal permits Cat, Dog, Fish { String breed();}
|                                  ^-^


4. No luck adding the third record either:

jshell> record Fish(String breed, String color) implements Animal{}

|  Error:
|  class is not allowed to extend sealed class: Animal
|  record Fish(String breed, String color) implements Animal{}
|  ^---------------------------------------------------------^

It seems like I should be able to update the interface by simply
/editing its declaration. It feels awkward and unintuitive to be 
unable to add additional implementations by /editing the permits
in the interface's declaration. 

Are there plans to add that capability to JShell at any point in the
future? 

Also, after several attempts at /editing the interface kept erroring,
I observed that JShell got in such a state that even after deleting
the interface to start over, adding the new record or recreating the 
interface crashed JShell.

Until I can pin down a more reproducible pattern though, I'll assume
that's more likely down to me having done something wrong.

TIA.




More information about the kulla-dev mailing list