jshell has trouble to register some records in the environment

Remi Forax forax at univ-mlv.fr
Thu Dec 26 12:24:36 UTC 2019


Hi all,
converting some materials for undergraduates, i have uncover a weird bug.

This snippet of code doesn't work in jshell
(jshell --enable-preview).

I get

jshell> record Rectangle(int width, int height) {
   ...>   double diagonal() {
   ...>     return Math.hypot(with, height);
   ...>   }
   ...> }
   ...> var rectangle2 = new Rectangle(4, 3);
   ...> System.out.println(rectangle2.diagonal());
|  Error:
|  cannot find symbol
|    symbol:   class Rectangle
|  var rectangle2 = new Rectangle(4, 3);
|                       ^-------^

So the class/record Rectangle doesn't seem to be registered ?
Changing it to

record Rectangle(int width, int height) {
  double diagonal() {
    return 5;
  }
}
var rectangle2 = new Rectangle(4, 3);
System.out.println(rectangle2.diagonal());

do work ??

Rémi


More information about the amber-dev mailing list