FULL PRODUCT VERSION :
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The JShell ignores the keyword 'final' in top-level declarations. This makes sense for methods and variables, but final top-level classes should be perfectly legal.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
jshell> final class A {}
| Warning:
| Modifier 'final' not permitted in top-level declarations, ignored
| final class A {}
| ^---^
| created class A
jshell> class B extends A {}
| created class B
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JShell should accept the keyword final for class A and should print an error for the declaration of class B such as "cannot inherit from final A".
ACTUAL -
The JShell ignores the keyword final for class A and allows class B to inherit from A.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
final class A {}
class B extens A {}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
You can experiment with final classes in the JShell inside a local context:
jshell> {
...> final class A{}
...> class B extends A{}
...> }
| Error:
| cannot inherit from final A
| class B extends A{}
| ^