In Java, there are two valid forms of the import
declaration:
import java.lang.Math;
import java.lang.Math.*;
In the latter, a wildcard is used. This form is known as a Type-Import-on-Demand declaration, but how is it different from the former? Does it also import the subpackages of java.lang.Math
?
What if Math
were a Type (e.g., a class)—would all of its inner classes be imported?
The documentation states:
Note: Another, less common form of import allows you to import the public nested classes of an enclosing class. For example, if the graphics.Rectangle class contained useful nested classes, such as Rectangle.DoubleWide and Rectangle.Square, you could import Rectangle and its nested classes by using the following two statements.
import graphics.Rectangle; import graphics.Rectangle.*;
Be aware that the second import statement will not import Rectangle.
So importing import java.lang.Math.*;
will not import the Math
class.
NOTE: You may also want to see Why is using a wild card with a Java import statement bad?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With