java - JVM 尖括号中的标识符导致内部方法错误

标签 java jvm identifier jls verifyerror

以下代码使用名为 <traitinit> 的方法,但被 JVM 拒绝并显示 VerifyError :

class Foo
{
    static void `<traitinit>`() // pseudocode identifier, not possible in Java
    {
    }

    static void test()
    {
        `<traitinit>`() // call the <traitinit> method
    }
}

错误:

java.lang.VerifyError: Illegal call to internal method
 Exception Details:
  Location:
    foo/bar/Foo.test()V @5: invokestatic
  Reason:
    Error exists in the bytecode

由于 JVM 已使用 <init><clinit>对于构造函数和类初始值设定项,这似乎是一个合理的错误消息。但是,JVM 规范中是否有任何部分明确定义了 internal method 的含义。是?我本以为它只保留上面的两个特定标识符,但情况似乎并非如此。

最佳答案

我自己找到了 JVM 规范的相关部分( §4.2.2. Unqualified Names ):

4.2.2. Unqualified Names

Names of methods, fields, local variables, and formal parameters are stored as unqualified names. An unqualified name must contain at least one Unicode code point and must not contain any of the ASCII characters . ; [ / (that is, period or semicolon or left square bracket or forward slash).

Method names are further constrained so that, with the exception of the special method names <init> and <clinit> (§2.9), they must not contain the ASCII characters < or > (that is, left angle bracket or right angle bracket).

(强调我的)

关于java - JVM 尖括号中的标识符导致内部方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36187698/

相关文章:

java - 当 jframe 未处于焦点时如何接受键盘快捷键?

java - java中静态变量内存什么时候释放?

java - 我可以手动复制 JVM 完成的一些优化吗?

java - Java 中的 dmp 文件?

arrays - Matlab:通过标识符更新数组中的元素

java - 使用 hadoop reducer 在将批量写入操作写入 mongodb 时检查重复记录

java - 文件上传 JSP 和 Servlet 2.5 未获取 Textarea 值

java - Swing Java 组件可见性控制

android-studio - Android Studio:不支持文字下划线错误

c++ - 在循环外声明的变量在 C++ 中是无法识别的