Pierre Thibault
Pierre Thibault

Reputation: 2073

How to access a Java class in the default package from jshell?

I am unable to access Java classes in the default package from jshell. I cannot import since the default package has no name and when I try to reference the name then I have an error:

jshell> Test.test(); | Error: | cannot find symbol | symbol:
variable Test | Test.test(); | ^--^

The only solution I found so far is using:

/open Test.java

Is it possible or is it a bug?

Here the code of Test.java:

public class Test {
    public static void test() {
        System.out.println("test");
    }
    public static void main(String[] args) {
        Test.test();
    }
}

Upvotes: 0

Views: 907

Answers (1)

user14959355
user14959355

Reputation: 96

This is not possible. From the docs,

Code in the default package, which is also known as the unnamed package, can’t be accessed from JShell.

Upvotes: 1

Related Questions