Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

用法

修饰变量

修饰基本类型:基本类型的值不可被改变

修饰引用:引用的指向不能被改变

被final修饰的基本类型和String类型会在编译器被放到常量池

修饰方法

方法不可被覆盖

修饰类

类不可被继承

原理

我们反编译如下代码:

1
2
3
4
5
6
7
8
9
public final class Tiger  {
private final String name ="tiget" ;
private final int a = 1;


public final void run(){
System.out.println("tiger is running");
}
}

得到:

7f26f50ff199d5bba671d34a3115a01.png 22ceb20e2a54fb5ca9e545e3b62b34d.png

评论