int i;
i = 30; / / this is easy to understand, because i is the basic data types ..
Integer I;
I = 30; / / this is not understood, because I was the object, but java seems to be no concept of operator overloading ...
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Reply
This is after JDK5.0 automatic packing function
Equal to Integer i = new Ingeger (30)
Reply:
Java just overloaded '+' This one operator.
The example cited is the landlord Java automatic packaging mechanisms have only basic data types.
Reply:
Automatic packing mechanism is not is when:
Target = basic data;
When assigned this way, the constructor automatically calls the basic parameters for the data.
Such as:
Integer I;
I = 30;
class CInt {
public CInt (int v) {
this.v = v;
}
private int v = 0;
}
/ / / / / / / / / / / / / / / / / / / / / / /
CInt int1;
int1 = 30; / / So why here and not automatically wraps it
?
Reply:
JAVA no operator overloading.
In addition to its own virtual machine defined.
Upstairs you infer, because the virtual machine does not implement this feature.
You can not think Integer this class with your class is the same.
Conversion between Integer and int, not a language feature, but a functional virtual machine implementation.
Like
for (int i: arr)
{.....}
You can not use foreach (int i: arr)
{.....}
Instead.
You say your foreach and also for the same?
Reply:
Here int1 assignment of 30 is wrong, because int1 is an object of type CInt can not assign it to a constant value.
Even the automatic packaging system, they can only put int packed into Integer, rather than packed into CInt.
class CInt {
public CInt (Integer v) {
this.v = v ;/ / here the Integer object assigned to the int variables used in the automatic packaging mechanism.
}
private int v = 0;
}
/ / / / / / / / / / / / / / / / / / / / / / /
CInt int1 = new CInt (30) ;/ / here the constant 30 automatic packaging of Integer object.
Reply:
Learn, remember what the book is easy to book speaking Java abandoned the confusing operator overloading, in fact wrong, or there + and = (package) is overloaded
------------------------- ----------------------------- AutoCSDN Signature -------------------- ----------------------------------
yard farm - yard farmers sow code grazing farms thoughts! 
No comments:
Post a Comment