当前位置:网站首页>final关键字的作用 final和基本类型、引用类型
final关键字的作用 final和基本类型、引用类型
2022-08-01 13:50:00 【Scyth1】
final四个作用
final修饰常量 ,值不可以被第二次修改
final修饰的类不可以被继承
final修饰的方法不可以被重写
final防止多线程下的指令重排序,保障线程安全
final修饰引用类型
final类型的数组防止引用类型整体指向
但是可以改变数组的内部
我们可以看到,arr数组是被final修饰的,但是经过arr[3] = 8;
对arr数组中其中一个元素进行更改后,数组下标为3的值发生了改变
final修饰基本类型
import java.util.*;
public class Test1{
public static void main(String[]args) {
final int a=90;
System.out.println(a);
a = 2;
System.out.println(a);
}
}
基本类型被final修饰以后不能进行二次修改
边栏推荐
猜你喜欢
8. How does the SAP ABAP OData service support the Create operation
gpio analog serial communication
Based on 10 years of experience in stability assurance, what are the three key questions to be answered in failure recovery?|TakinTalks big coffee sharing
【2022蓝帽杯】file_session && 浅入opcode
8. SAP ABAP OData 服务如何支持创建(Create)操作
全链路灰度在数据库上我们是怎么做的?
windows IDEA + PHP+xdebug 断点调试
响应式2022英文企业官网源码,感觉挺有创意的
Programmer's Romantic Tanabata
搭建LNMT架构
随机推荐
魔众短链接系统 v3.9.0
fh511小风扇主控芯片 便携式小风扇专用8脚IC 三档小风扇升压芯片sop8
什么是一致性哈希?可以应用在哪些场景?
LeetCode_动态规划_中等_313.超级丑数
Multi-threaded cases - blocking queue
What Can Service Mesh Learn from SDN?
超全!全国近90所大学考研报录比汇总!
性能测试入门指南
快速理解拉格朗日乘子法
AD单片机九齐单片机NY8B062D SOP16九齐
8. How does the SAP ABAP OData service support the Create operation
观察者模式
A Beginner's Guide to Performance Testing
Qt实战案例(56)——利用QProcess实现应用程序重启功能
VIP的实现原理
关于Request复用的那点破事儿。研究明白了,给你汇报一下。
Based on 10 years of experience in stability assurance, what are the three key questions to be answered in failure recovery?|TakinTalks big coffee sharing
sql中常用到的正则表达
分布式中的CAP原理
全球都热炸了,谷歌服务器已经崩掉了