No, because wrapper classes (and all other classes in java.lang)
are automatically imported.
public class Autoboxing
{
public static void main ( String[] args )
{
Integer value = 103 ; // automatically create a wrapper for the value 103
Double dvalue = -32.78 ; // automatically create a wrapper for the value -32.78
System.out.println( "Integer object holds: " + value );
System.out.println( "Double object holds: " + dvalue );
}
}
Here is the same program as above.
But now,
the wrappers for the values are created without explicitly using new.
This statement creates an Integer wrapper, puts the value 103 in it,
and assigns its reference to value:
Integer value = 103 ;
This statement does the same thing with more explicit syntax:
Integer value = new Integer(103);
This feature is called autoboxing. It will be useful in the future.
Does the following code look suspicious?
public class Unboxing
{
public static void main ( String[] args )
{
Integer value = 103 ; // automatically create a wrapper for the value 103
int x = 41 ;
int sum = value + 41;
System.out.println( "The sum is: " + sum );
}
}