以下代码使用名为 <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/