1. All basic types have a class corresponding to them, which is often referred to as wrappers.
2. The object wrapper class is immutable, that is, once the wrapper is constructed, it is not allowed to change the value in which the wrapper is wrapped. Object wrappers are final, so they cannot be defined by subclasses.
3. Suppose you define an integer array list, and the type parameter in angle brackets does not allow the base type, that is, Arraylist<int> is not allowed, and you can use the integer object wrapper class.
array<integer> L = new arraylist<> ();
4. Boxing and unpacking are compiler-approved, not virtual machines. The compiler inserts the necessary method calls when generating bytecode for the class. The virtual machine simply executes these bytecode.
5. In the method of variable number of parameters, ... is part of the Java code, which indicates that this method can receive any number of objects.
public static double Max (double ... values) { }
6. When comparing the values of two enumerated types, you never need to call equals, and you can use "= =" directly.
7. All enum types are subclasses of the enum class.
8. Each enumeration class has a
The static Values method, which returns an array that contains all the enumerations that are worth.
Color[] values = Color.values ();
The 9.ordinal method returns the position of the enumeration constant in the enum declaration, starting at 0.
Related instance Code
Import java.util.*;p ublic class Test {public static void main (string[] args) {Scanner in = new Scanner (system.in); System.out.println ("Please enter a color: (Red,blue,white,green,yello)"); String i = In.next (). toUpperCase (); Color C = enum.valueof (Color.class, i); SYSTEM.OUT.PRINTLN ("color =" + c); SYSTEM.OUT.PRINTLN ("abbreviation =" + c.getabbreviation ()); if (c = = color.red) System.out.println ("You chose the same color as I liked!") "); color[] G = color.values (); for (Color e:g) {System.out.print (E + "");} System.out.println (); System.out.println (Color.RED.ordinal ());} Enum color{red ("Red"), Green ("green"), BULE ("Blue"), White ("Bai"), Yello ("yellow");p rivate Color (String abbreviation) { this.abbreviation = abbreviation;} Public String getabbreviation () {return abbreviation;} private String abbreviation;}}
result Output
My Java Learning notes (11) About boxing, parameter mutable methods, and enumeration types