zno2

final static T

    /**
     * An empty table instance to share when the table is not inflated.
     */
    static final Entry<?,?>[] EMPTY_TABLE = {};

final 修饰的类不能被继承

final 修饰的方法不能被重写

final 修饰的变量不能被重新赋值

 

不能被二次赋值

The final field Test1.PERSON_LIST cannot be assigned

不能不赋值

The blank final field PERSON_LIST may not have been initialized

赋值的3种途径:

  1. 赋默认值
  2. 构造块中对其进行赋值
  3. 构造函数中对其进行赋值

 

回到例子中,final修饰成员变量,该变量类型是T

 

此时final的意思是 为该变量在堆内存中分配一块固定的内存,不允许重新分配内存。

但是可以对该内存进行操作。

package map;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

public class Test1 {
    
    static final List<String> PERSON_LIST = new ArrayList<String>();

    @Test
    public void test() {
        PERSON_LIST.add("Lina");
        PERSON_LIST.add("Jone");
        System.out.println(PERSON_LIST);
    }

}

打印结果:

[Lina, Jone]

posted on 2016-08-05 18:42  zno2  阅读(155)  评论(0编辑  收藏  举报

导航