首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有人了解java注释"java.lang.Synthetic“的背景?

有没有人了解java注释"java.lang.Synthetic“的背景?
EN

Stack Overflow用户
提问于 2013-09-13 00:08:01
回答 2查看 604关注 0票数 1

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

EN

回答 2

Stack Overflow用户

发布于 2013-09-13 07:54:19

也许这就是你要找的?

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

票数 0
EN

Stack Overflow用户

发布于 2013-09-17 04:00:52

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

通过以下方式:

代码语言:javascript
复制
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);
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18769282

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档