Wrapper classes in Java. Boxing, Autoboxing, Unboxing
* Autoboxing - converting primitive types to objects.
* Unboxing - converting objects to primitive types.
Primitive types - Wrapper class
boolean Boolean
char Character
byte Byte
short Short
int Integer
long Long
float Float
double Double
package autoboxing;
public class Main {
public static void main(String[] args) {
int i = 100;
Integer j = Integer.valueOf(i); // boxing
Integer c = i; // autoboxing
Integer number = new Integer(10);
int d = number.intValue(); // unboxing
int e = number; // unboxing
}
}
Комментарии
Отправить комментарий