You should not need to import any class in java.lang
. The class in java.lang
are normally available to be used without an explicit import.
"A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package
java.lang
." - JLS Chapter 7.
The only cases where it may be necessary to explicitly import a java.lang
class are when you have declared another class with the same name as a java.lang
class. In some circumstances, that class may take precedence over the class in java.lang
, forcing you to either import the java.lang
class, or use its fully qualified name.
It is a good idea to avoid declaring classes with the same names as commonly used Java library classes, especially those in java.lang
.