What does “()V” mean in a class signature?

前端 未结 3 1984
广开言路
广开言路 2021-01-31 10:09

I created a constructor with Javassist which has no real method

CtConstructor c = CtNewConstructor.make ( argTypes, null, newClass );

When I\'

相关标签:
3条回答
  • 2021-01-31 10:27

    The JVM uses a compact way of storing method signatures, of which constructors are considered a special case.

    For your example:

    • () indicates a method taking no arguments
    • V indicates that it returns nothing

    The other parts of the scheme are:

    • B - byte
    • C - char
    • D - double
    • F - float
    • I - int
    • J - long
    • S - short
    • V - void
    • Z - boolean
    • [ - array of the thing following the bracket
    • L [class name] ; - instance of this class, with dots becoming slashes
    • ( [args] ) [return type] - method signature

    For example:

    public int foo(String bar, long[][] baz)
    

    would become

    (Ljava/lang/String;[[J)I
    

    See the spec at Sun^H^H^HOracle's web site

    0 讨论(0)
  • 2021-01-31 10:28

    "V" determines the result type "void"

    0 讨论(0)
  • 2021-01-31 10:28

    V in a type signature means void type. Bytecode does not differentiate constructors from other methods (other than using special method name).

    0 讨论(0)
提交回复
热议问题