Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
Accelerator
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Type
/
to search
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
Interview-Notes
/
toBeTopJavaer
Public
forked from
hollischuang/toBeTopJavaer
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
toBeTopJavaer
/
basics
/
java-basic
/
enum-impl.md
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
45 lines (38 loc) · 1.79 KB
master
Breadcrumbs
toBeTopJavaer
/
basics
/
java-basic
/
enum-impl.md
Copy path
Top
File metadata and controls
Code
Blame
45 lines (38 loc) · 1.79 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Java
SE5提供了一种新的类型
-
Java的枚举类型
,
关键字enum可以将一组具名的值的有限集合创建为一种新的类型
,
而这些具名的值可以作为常规的程序组件使用
,
这是一种非常有用的功能
。
要想看源码
,
首先得有一个类吧
,
那么枚举类型到底是什么类呢
?
是enum吗
?
答案很明显不是
,
enum就和class一样
,
只是一个关键字
,
他并不是一个类
,
那么枚举是由什么类维护的呢
,
我们简单的写一个枚举
:
public
enum
t
{
SPRING
,
SUMMER
;
}
然后我们使用反编译
,
看看这段代码到底是怎么实现的
,
反编译后代码内容如下
:
public
final
class
T
extends
Enum
{
private
T
(
String
s
,
int
i
)
{
super
(
s
,
i
);
}
public
static
T
[]
values
()
{
T
at
[];
int
i
;
T
at1
[];
System
.
arraycopy
(
at
=
ENUM$VALUES
,
0
,
at1
=
new
T
[
i
=
at
.
length
],
0
,
i
);
return
at1
;
}
public
static
T
valueOf
(
String
s
)
{
return
(
T
)
Enum
.
valueOf
(
demo
/
T
,
s
);
}
public
static
final
T
SPRING
;
public
static
final
T
SUMMER
;
private
static
final
T
ENUM$VALUES
[];
static
{
SPRING
=
new
T
(
"SPRING"
,
0
);
SUMMER
=
new
T
(
"SUMMER"
,
1
);
ENUM$VALUES
= (
new
T
[] {
SPRING
,
SUMMER
});
}
}
通过反编译后代码我们可以看到
,
public
final
class
T
extends
Enum
,
说明
,
该类是继承了Enum类的
,
同时final关键字告诉我们
,
这个类也是不能被继承的
。
当我们使用enmu来定义一个枚举类型的时候
,
编译器会自动帮我们创建一个final类型的类继承Enum类
,
所以枚举类型不能被继承
。
You can’t perform that action at this time.