1

有没有人有关于 java 注释“java.lang.Synthetic”的背景。我在列出 JavaEE 企业应用程序中的注释出现时遇到了它。注释出现在 com.sun.xml 包中的几个类上。我找不到此注释的文档。它是由 java 编译器生成的官方注释,用于指示合成访问器(例如,参见Synthetic accessor method warning)?这似乎不太可能,因为没有可用的文档。然而,在包“java.lang”中的放置使注释有点官方外观。

4

2 回答 2

0

细读 ASM 表明这是 ASM 添加的“虚拟”参数注释。

看:

http://asm.ow2.org/index.html

http://websvn.ow2.org/filedetails.php?repname=asm&path=%2Ftrunk%2Fasm%2Fsrc%2Forg%2Fobjectweb%2Fasm%2FClassReader.java

和:

private void readParameterAnnotations(int v, final String desc,
        final char[] buf, final boolean visible, final MethodVisitor mv) {
    int i;
    int n = b[v++] & 0xFF;
    // workaround for a bug in javac (javac compiler generates a parameter
    // annotation array whose size is equal to the number of parameters in
    // the Java source file, while it should generate an array whose size is
    // equal to the number of parameters in the method descriptor - which
    // includes the synthetic parameters added by the compiler). This work-
    // around supposes that the synthetic parameters are the first ones.
    int synthetics = Type.getArgumentTypes(desc).length - n;
    AnnotationVisitor av;
    for (i = 0; i < synthetics; ++i) {
        // virtual annotation to detect synthetic parameters in MethodWriter
        av = mv.visitParameterAnnotation(i, "Ljava/lang/Synthetic;", false);
        if (av != null) {
            av.visitEnd();
        }
    }
    for (; i < n + synthetics; ++i) {
        int j = readUnsignedShort(v);
        v += 2;
        for (; j > 0; --j) {
            av = mv.visitParameterAnnotation(i, readUTF8(v, buf), visible);
            v = readAnnotationValues(v + 2, buf, true, av);
        }
    }
}
于 2013-09-16T20:00:51.787 回答
0

也许这就是你要找的东西?

http://javapapers.com/core-java/java-synthetic-class-method-field/

于 2013-09-12T23:54:19.467 回答