java - 是否在任何地方指定匿名类的数量从 1 开始?

标签 java class specifications

This answer另一个问题表明,作为通过反射查找匿名类的解决方法,只需尝试所有名称,从 ...$1 开始并向上计数,直到找不到更多名称。这是否保证找到所有内部类,或者是否存在它们从 0 开始或某些数字被遗漏(无论出于何种原因)的情况?

最佳答案

JLS 13.1指定:

The class or interface must be named by its binary name, which must meet the following constraints:

  • The binary name of a top level type (§7.6) is its canonical name (§6.7).
  • [...]
  • The binary name of an anonymous class (§15.9.5) consists of the binary name of its immediately enclosing type, followed by $, followed by a non-empty sequence of digits.

所以从理论上讲,它不必从 1 开始,但它必须类似于 EnclosingClass$N,其中 N 是一个数字。

关于java - 是否在任何地方指定匿名类的数量从 1 开始?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12267459/

相关文章:

Java 本地嵌套类和访问 super 方法

php - 扩展 MySQLi 类以在页面上解释 SQL 查询

specifications - QXF 文件格式规范

css - 识别匿名 block 框

java - 我将如何对此 JSON 解析执行 Angular JS ng-repeat ?

java - 在 Eclipse 中运行我签名的发布 keystore 时出现问题

java - JSlider 适合 JPanel 的宽度

java - 动态加载类并获取带注释的类

java - 错误;找不到标志;符号: variable super

clojure 规范 fdef 不起作用 - 在传递递归定义时