把可变对象 定义为 final究竟会怎样?

看个例子吧


final List list = new ArrayList();

list.add("hello");       //可以顺利执行。这说明final对象仍然可以被改变

list = new ArrayList();  //编译不能通过。意味着final的引用本身不能被切换

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.