Why Java methods with varargs identified as transient?

后端 未结 3 1758
闹比i
闹比i 2021-02-07 02:56

I was playing with Java Reflection API and observed that methods with variadic argument list become transient. Why is that and what does transient keyword mean in t

3条回答
  •  耶瑟儿~
    2021-02-07 03:15

    The flag for a transient field has been overloaded in the context of a method to mean that the method is a vararg method.

    Likewise, the flag for a volatile field has been overloaded in the context of a method to mean that the method is a bridge method.

    See: http://java.sun.com/docs/books/vmspec/2nd-edition/ClassFileFormat-Java5.pdf

    pages 118-122 (or 26-30 in the PDF file)

    Update

    Reading the source code for Modifier.java confirms the first sentence of this answer ("The flag for a transient field has been overloaded"). Here's the relevant source code:

    // Bits not (yet) exposed in the public API either because they
    // have different meanings for fields and methods and there is no
    // way to distinguish between the two in this class, or because
    // they are not Java programming language keywords
    static final int BRIDGE    = 0x00000040;
    static final int VARARGS   = 0x00000080;
    static final int SYNTHETIC = 0x00001000;
    static final int ANNOTATION  = 0x00002000;
    static final int ENUM      = 0x00004000;
    static final int MANDATED  = 0x00008000;
    

提交回复
热议问题