Skip to content

Update 22-Enumerations.md #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 11, 2020
Merged

Update 22-Enumerations.md #528

merged 2 commits into from
Aug 11, 2020

Conversation

cjiayang
Copy link
Contributor

@cjiayang cjiayang commented Aug 4, 2020

枚举→values方法的神秘之处→去掉多余的0

枚举→values方法的神秘之处→去掉多余的0
@@ -348,7 +348,7 @@ final class Explore extends java.lang.Enum<Explore> {

由于擦除效应(在[泛型 ]() 章节中介绍过),反编译无法得到 Enum 的完整信息,所以它展示的 Explore 的父类只是一个原始的 Enum,而非事实上的 Enum\<Explore\>。

由于 values() 方法是由编译器插入到 enum 定义中的 static 方法,所以,如果你将 enum 实例向上转型为 Enum,那么 values() 方法就不可访问了。不过,在 Class 中有一个 getEnumConstants0 方法,所以即便 Enum 接口中没有 values0 方法,我们仍然可以通过 Class 对象取得所有 enum 实例。
由于 values() 方法是由编译器插入到 enum 定义中的 static 方法,所以,如果你将 enum 实例向上转型为 Enum,那么 values() 方法就不可访问了。不过,在 Class 中有一个 getEnumConstants 方法,所以即便 Enum 接口中没有 values 方法,我们仍然可以通过 Class 对象取得所有 enum 实例。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把括号补上

@sjsdfg sjsdfg merged commit 6f76129 into lingcoder:master Aug 11, 2020
fengjixuchui added a commit to fengjixuchui/OnJava8 that referenced this pull request Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants