有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

有人有java注释“java.lang.Synthetic”的背景吗?

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


共 (2) 个答案

  1. # 2 楼答案

    仔细阅读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);
            }
        }
    }