How does Java decide when to import?

后端 未结 9 1374
时光取名叫无心
时光取名叫无心 2020-11-27 20:55

Why doesn\'t Java need to import classes like Integer, String, etc. while it needs to import other classes?

相关标签:
9条回答
  • 2020-11-27 21:21

    Classes in the java.lang package do not need to be imported (the compiler acts like they are always imported). This package includes core classes such as String, Enum, Runnable, NullPointerException, and of course, the primitive wrapper classes such as Integer and Double.

    0 讨论(0)
  • 2020-11-27 21:24

    java.lang package is imported by default, no need to explicitly import it.

    0 讨论(0)
  • 2020-11-27 21:29

    For the question for "Is java.lang the only one auto-import package?" There is two packages.

    1. java.lang
    2. unnamed

    you can look up here for more. https://www.quora.com/Which-package-is-available-by-default-in-java

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