Importing Package-Private Classes to JShell

痴心易碎 提交于 2019-12-04 09:27:41

As far as i know (correct me if i am wrong), you cannot create a Class in a specific package using JShell (classes created within JShell are always in the default package).

That being said, you cannot access your package-private classes from within JShell. This is "normal" Java behaviour.

From the JEP#220 - The Java Shell (Read-Eval-Print Loop)

A snippet may not declare a package or a module. All JShell code is placed in a single package in an unnamed module. The name of the package is controlled by JShell.

That is the reason probably why you are not able to declare a package within JShell.


As the tool documentation suggests though you can give this a try:-

The default startup script consists of several common imports. You can personalize your startup entries with the /set start command.

where you can set the classpath or the modulepath of the class you would make use of :

jshell --class-path C:\Users\Sylvaenn\OneDrive\Documents\Programs\Java\cls
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!