美文网首页Java学习笔记想法Java 杂谈
Retrieving and Parsing Field Mod

Retrieving and Parsing Field Mod

作者: 日更专用小马甲 | 来源:发表于2019-04-09 15:13 被阅读1次

本系列翻译自Oracle官方教程,半翻译,半读后感性质。文末会附上原文链接。

一开始跟类一样,[1]从几个角度介绍了修饰符:

  • public/protect/private
  • volatile/transient(字段特有)
  • final
  • static
  • 注解

接下来,介绍了两个函数:

  • Field.isSynthetic()用于判断是否是编译器生成的
  • Field.isEnumConstant()用于判断是否是枚举常量(enum constant)

在一个类中,如果定义了一个非静态的内部类,则会由编译器在该内部类中,生成一个指向最外层外部类的字段(通常用this$0表示)。

public class Outer {
    class Inner {
        // this$0
    }
}

… however commonly used fields include this$0 for inner classes (i.e. nested classes that are not static member classes) to reference the outermost enclosing class …

另外,该字段是非public的,只能由Class.getDeclaredFields()返回。

原文链接:Retrieving and Parsing Field Modifiers

相关文章

网友评论

    本文标题:Retrieving and Parsing Field Mod

    本文链接:https://www.haomeiwen.com/subject/ctyviqtx.html