What other than java.lang packages are imported automatically in the JShell?

179 views Asked by At

I've observed that in the JShell session, not only package "java.lang", but quite a few other packages (that are not imported automatically in the Java class files, e.g. LinkedList, Math and several other types) seem to be imported, by default.

I wonder, what other packages are available, by default, in the JShell session, and what motivates this distinction from the normal class files?

I could not find anything on JEP 222, neither the motivation of this auto/implicit import , nor the documentation of - what is actually imported.

1

There are 1 answers

0
M A On BEST ANSWER

You can run /import to find out:

jshell> /import
|    import java.io.*
|    import java.math.*
|    import java.net.*
|    import java.nio.file.*
|    import java.util.*
|    import java.util.concurrent.*
|    import java.util.function.*
|    import java.util.prefs.*
|    import java.util.regex.*
|    import java.util.stream.*

https://docs.oracle.com/en/java/javase/11/tools/jshell.html