Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "()V" mean in a class signature?

I created a constructor with Javassist which has no real method

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

When I'm trying to put out the signature of this class

c.getSignature(); 

I get

public Echo ()V 

I'm confused what "V" means? I expected either public Echo (); or something similar...

like image 778
Evils Avatar asked Mar 28 '12 14:03

Evils


People also ask

What does V mean in Java?

E - Element (used extensively by the Java Collections Framework) K - Key. N - Number. T - Type. V - Value.

What is a class signature?

class Signature { } A signature is a static description of the parameter list of a code object. That is, it describes what and how many arguments you need to pass to the code or function in order to call it. Passing arguments to a signature binds the arguments, contained in a Capture, to the signature.

What does method signatures mean in Java?

The method signature in java is defined as the structure of the method that is designed by the programmer. The method signature is the combination of the method name and the parameter list. The method signature depicts the behavior of the method i.e types of values of the method, return type of the method, etc.

What is the method signature for a class constructor?

Constructor syntax A constructor is a method whose name is the same as the name of its type. Its method signature includes only an optional access modifier, the method name and its parameter list; it does not include a return type. The following example shows the constructor for a class named Person .


2 Answers

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

like image 172
Simon Nickerson Avatar answered Oct 05 '22 15:10

Simon Nickerson


"V" determines the result type "void"

like image 40
Philip Helger Avatar answered Oct 05 '22 13:10

Philip Helger