What is the internal identification of the Java method?

As you know, in Java, the method name is not enough to distinguish between different methods.

I think (it may be wrong) to distinguish a method, it needs the following information:

(className, methodName, methodParameters)

Further,

  • How to determine the method more efficiently within the country?
  • I heard about the "id method". Does this mean that there is a mapping between the above triple and the integer, so the JVM uses only the method identifier after parsing?
  • If so, is it in the symbol table?

Thank!

+5
source share
4 answers

This is a CONSTANT_NameAndType_info structure that points to a method handle.

This is mainly the name of the method, parameter types and (somewhat surprisingly) the return type.

+6

, , , :

  • JNI, , JVM ( JNI) Java.

  • , . " " java.lang.reflect.Method , , . ?

  • , JVM . , , , , JVM, , . , :

    Class clazz = String.class;
    Method method = clazz.getDeclaredMethod("charAt", Integer.TYPE);
    System.out.println(method.getName());
    

, String , util charAt, int String.

, - :

(methodName, methodParameters)

, JVM, , , , , . , , , , .

JNI, . ,

long f(int i, Class c);

:

"(ILjava/lang/Class;)J"

, .

( @Lawence) . .

+1

Java .

, myMethod(int a, int b) MyClass, com.mypackage, java com.mypackage.MyClass.myMethod(int a , int b).

, Class Loader, .

, , , . java . java.lang.Thread .

0

1) ?

? , "" "". -, JIT, /, , API , . .

2) " id". , , JVM ?

classfile - , / , JIT .

JVM Java.

3) , ?

. , " ". , , . , API- Java , getDeclaredMethod(...) Method.

0

All Articles