java枚举的原理是什么
作者:SunnyJourney
时间:2023-04-25
来源:互联网
浏览:0
1、枚举是继承了抽象类Enum的类。Seasonextendsjava.lang.Enum2、通过一段静态代码块初始化枚举。static{};descriptor:()Vflags:ACC_STATICCode:stack=4,locals=0,args_size=00:new#4//classio/github/yehongzhi/user/redisLock/Season3:dup4:ldc#7//StringSPRING6:iconst_07:invokespecial#8//Method"":(L
1、枚举是继承了抽象类Enum的类。
Season extends java.lang.Enum
2、通过一段静态代码块初始化枚举。
static {};
descriptor: ()V
flags: ACC_STATIC
Code:
stack=4, locals=0, args_size=0
0: new #4 // class io/github/yehongzhi/user/redisLock/Season
3: dup
4: ldc #7 // String SPRING
6: iconst_0
7: invokespecial #8 // Method "":(Ljava/lang/String;I)V
10: putstatic #9 // Field SPRING:Lio/github/yehongzhi/user/redisLock/Season;
13: new #4 // class io/github/yehongzhi/user/redisLock/Season
16: dup
17: ldc #10 // String SUMMER
19: iconst_1
20: invokespecial #8 // Method "":(Ljava/lang/String;I)V
23: putstatic #11 // Field SUMMER:Lio/github/yehongzhi/user/redisLock/Season;
26: new #4 // class io/github/yehongzhi/user/redisLock/Season
29: dup
30: ldc #12 // String AUTUMN
32: iconst_2
33: invokespecial #8 // Method "":(Ljava/lang/String;I)V
36: putstatic #13 // Field AUTUMN:Lio/github/yehongzhi/user/redisLock/Season;
39: new #4 // class io/github/yehongzhi/user/redisLock/Season
42: dup
43: ldc #14 // String WINTER
45: iconst_3
46: invokespecial #8 // Method "":(Ljava/lang/String;I)V
49: putstatic #15 // Field WINTER:Lio/github/yehongzhi/user/redisLock/Season;
52: iconst_4
53: anewarray #4 // class io/github/yehongzhi/user/redisLock/Season
56: dup
57: iconst_0
58: getstatic #9 // Field SPRING:Lio/github/yehongzhi/user/redisLock/Season;
61: aastore
62: dup
63: iconst_1
64: getstatic #11 // Field SUMMER:Lio/github/yehongzhi/user/redisLock/Season;
67: aastore
68: dup
69: iconst_2
70: getstatic #13 // Field AUTUMN:Lio/github/yehongzhi/user/redisLock/Season;
73: aastore
74: dup
75: iconst_3
76: getstatic #15 // Field WINTER:Lio/github/yehongzhi/user/redisLock/Season;
79: aastore
80: putstatic #1 // Field $VALUES:[Lio/github/yehongzhi/user/redisLock/Season;
83: return 这段静态代码块的作用就是生成四个静态常量字段的值,还生成了$VALUES字段,用于保存枚举类定义的枚举常量。
3、关于values()方法,这是一个静态方法,作用是返回该枚举类的数组,底层实现原理,其实是这样的。
public static io.github.yehongzhi.user.redisLock.Season[] values(); Code: 0: getstatic #1 // Field $VALUES:[Lio/github/yehongzhi/user/redisLock/Season; 3: invokevirtual #2 // Method "[Lio/github/yehongzhi/user/redisLock/Season;".clone:()Ljava/lang/Object; 6: checkcast #3 // class "[Lio/github/yehongzhi/user/redisLock/Season;" 9: areturn
作者最新文章
图几
2026-09-16 17:43
SQL中ROUND函数对0.5的处理机制及强制四舍五入方法
2026-09-15 14:19
JS金额计算怎么避免四舍五入误差
2026-09-14 17:32
韩国8月携号转网数据:Galaxy Z8系列iPhone用户转化率约为Z7系列2倍
2026-09-08 17:02
AE基础教程:如何创建合成并制作关键帧动画
2026-09-04 09:27
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多
Windows 10
Windows
Windows 10 是一款微软推出的经典操作系统,拥有硬件兼容性与多任务处理能力。它更偏向把系统状态查看和常用调节动作放在一起,适合需要持续观察和微调设备状态的场景。
极度公式
Windows/macOS/Linux
极度公式是一款跨平台专业LaTeX公式识别编辑软件,支持OCR公式识别和多平台编辑。和使用说明,避免使用,享受完整功能与稳定支持。做扫描整理、文字提取和表格转换时,它能把识别后的处理步骤接得更顺,资料录入这类场景会省下不少时间。
















