java中枚举的原理是什么
java中枚举的原理是什么?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

建网站原本是网站策划师、网络程序员、网页设计师等,应用各种网络程序开发技术和网页设计技术配合操作的协同工作。创新互联专业提供网站制作、网站建设,网页设计,网站制作(企业站、响应式网站开发、电商门户网站)等服务,从网站深度策划、搜索引擎友好度优化到用户体验的提升,我们力求做到极致!
Java可以用来干什么
Java主要应用于:1. web开发;2. Android开发;3. 客户端开发;4. 网页开发;5. 企业级应用开发;6. Java大数据开发;7.游戏开发等。
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
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。
当前标题:java中枚举的原理是什么
标题来源:http://www.jxjierui.cn/article/gsjgoj.html


咨询
建站咨询
