自动装箱和自动拆箱

 1 package com.isoftstone.iics.bizsupport.epartner.fh;
 2 
 3 import java.util.ArrayList;
 4 import java.util.List;
 5 
 6 import org.junit.Test;
 7 import org.omg.CORBA.IntHolder;
 8 
 9 public class IntegerTest {
10     
11     /**
12      * boolean char byte<=127 short int 介于-127--128会被包装到固定的对象中
13      * 
14      * 装箱和拆箱是编译器认可的,虚拟机只是执行字节码
15      * <p>Title: test</p>
16      * <p>Description: TODO</p>
17      * @author 冯浩  2017年4月12日 上午8:15:36
18      */
19     @Test
20     public void test(){
21         List<Integer> list=new ArrayList<Integer>();
22         list.add(1);
23 //        list.add(Integer.valueOf(1));
24         
25         int q = list.get(0);
26         int intValue = list.get(0).intValue();
27         
28         Integer a=100;
29         Integer b=100;
30         if(a==b){
31             System.out.println("a==b");
32         }
33 //        IntHolder a=5;
34         Integer a1=1000;
35         Integer b1=1000;
36         if(a1==b1){
37             System.out.println("a1==b1");
38         }
39     }
40     
41     @Test
42     public void test2(){
43         int a=1;
44         IntHolder b=new IntHolder(a);
45         this.add(b);
46         System.out.println(b.value);
47         
48     }
49     
50     public void add(IntHolder a){
51         a.value+=1;
52     }
53 
54 }

枚举类测试

 1 package com.isoftstone.iics.bizsupport.epartner.fh;
 2 
 3 /**
 4  * 
 5  * <P>Description: TODO枚举类测试</P>
 6  * @ClassName: EnumTest
 7  * @author 冯浩  2017年4月12日 上午8:38:37
 8  * @see TODO
 9  */
10 public class EnumTest {
11     
12     public static void main(String[] args) {
13         Model value = Enum.valueOf(Model.class, "MW");
14         String name = value.getName();
15         System.out.println(name);
16         
17     }
18 
19 }
20 
21   enum Model{
22       
23       MW("1","梦网"),MD("2","漫道"),ALIYUN("3","阿里云");
24       private String index;
25       private String name;
26     public String getIndex() {
27         return index;
28     }
29     public void setIndex(String index) {
30         this.index = index;
31     }
32     public String getName() {
33         return name;
34     }
35     public void setName(String name) {
36         this.name = name;
37     }
38     private Model(String index, String name) {
39         this.index = index;
40         this.name = name;
41     }
42       
43     
44 }
原文地址:https://www.cnblogs.com/nihaofenghao/p/6697581.html