Devender Goyal
Devender Goyal

Reputation: 35

Import statement clarification

What is the difference between "import java.lang.Integer;" and " import java.lang.Integer.*;".

I have read on internet that the Integer is a class inside the lang package. If this is true then then " import java.lang.Integer.*;" should give an compilation error because the statement " import java.lang.Integer.*;" mean to import all the classes inside the package Integer but Integer is not a package it is a class.

But both statements compile without any error.

Please clarify. Thanks a lot in advance.

Upvotes: 2

Views: 446

Answers (2)

Sam
Sam

Reputation: 841

import java.lang.Integer.*;

The above statement is a less common form of import, allows you to import the public nested classes of an enclosing class(in this case Integer class).

Consider 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.

Upvotes: 0

Divyang Patel
Divyang Patel

Reputation: 347

If i will write "import java.lang.Integer;" so its a particular find Integer Function only.
if I will write "import java.lang.Integer.*; so Its all function Included which Extension of "java.lang.integer".

Upvotes: 1

Related Questions