There are two types of data in Java:
1. Basic type: long,int,byte,float,double
2. Object type: long,integer,byte,float,double All other Java-provided, or classes you create yourself.
Where long is called Long's wrapper class. Integer, Byte, and float are similar, and the first name of the generic wrapper class is the beginning of the capitalization of the numeric name.
What is a wrapper class?
In Java, sometimes the operation must be between two classes of objects, do not allow the operation between the object and the number. So there needs to be an object that wraps the numbers so that the object can be operated on with another object.
For example, we can define a class:
[Java]View Plaincopy
- Public class Long {
- int i=0;
- Public Long (int i) {
- this.i=i;
- }
- }
This long is a wrapper class that wraps an integer value, which can then be used to write operator overloading to support certain operations. You can assign a value at this time:
Long L = new long (10);
Now the variable L is an object, not a number.
Long is the original data type, there is no attribute method, only mathematical operation, Long is the corresponding reference data type long, it has methods and properties, a no method property, a method attribute, this is their difference.
Look at the following applet:
[Java]View Plaincopy
- Long L = 1;
- Long L1 = new Long (1);
- Long L2 = New Long (1);
- if (l = = L1) {
- System.out.println ("=====l and L1 equal =====");
- }
- if (L = = L2) {
- System.out.println ("=====l and L2 equal =====");
- }
- if (L1 = = L2) {
- System.out.println ("=====l1 and L2 equal =====");
- }
Output:
[Plain]View Plaincopy
- =====l and L1 equal =====
- =====l and L2 equal =====
If you replace the condition of the third if statement with "L1.equals (L2)", the output will become:
[Plain]View Plaincopy
- =====l and L1 equal =====
- =====l and L2 equal =====
- =====L1 and L2 equal =====
It can also be seen that the variable defined by long is a long object, while the variable defined by long is a numeric variable with a longer shape.
ID with a long or long?
Hibernate, El expression and so on are packaging types, with a long type can reduce the box/unboxing;
In Hibernate, the type of the self-increasing hid in the entity is defined with a long rather than a long. Otherwise, a marshallingerror:null error will appear during the DWR matching process.
Whether to choose long or long this also depends on the specific environment, if you think this property can not be null, then use long, because it defaults to 0, if this field can be null, then you should choose Long.
http://blog.csdn.net/liushuijinger/article/details/30726433
Do you know what the difference is between long and long?