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

我是研究僧i 提交于 2019-12-02 16:46:39

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

"V" determines the result type "void"

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!