final variables are not functioning well in jshell

后端 未结 1 1172
名媛妹妹
名媛妹妹 2020-12-18 04:37

I am working with jshell of JDK9.

I just created a final variable and assigned a value to it. And in the next line i just modified the value. And to my surprise, the

1条回答
  •  隐瞒了意图╮
    2020-12-18 05:32

    While creating a final variable at the top-level is not supposed to be practiced. But I guess there is no hard way of restricting such usages.

    From the documentation around JShell.eval

    The modifiers public, protected, private, static, and final are not allowed on op-level declarations and are ignored with a warning.

    Synchronized, native, abstract, and default top-level methods are not allowed and are errors.

    If a previous definition of a declaration is overwritten then there will be an event showing its status changed to OVERWRITTEN, this will not occur for dropped, rejected, or already overwritten declarations.

    The warning stated above is quite visible when you execute jshell in verbose mode as follows:

    0 讨论(0)
提交回复
热议问题