Compute a Java function's signature

前端 未结 6 1771
傲寒
傲寒 2021-02-03 22:30

Is there a way to compute a Java class\'s method\'s signature? A signature
like ([Ljava/lang/String;)V represents a function that takes a

6条回答
  •  不思量自难忘°
    2021-02-03 22:37

    From the JLS, §8.4.2:

    8.4.2 Method Signature

    The signature of a method consists of the name of the method and the number and types of formal parameters to the method. A class may not declare two methods with the same signature, or a compile-time error occurs.

    The example:

    class Point implements Move {
      int x, y;
      abstract void move(int dx, int dy);
      void move(int dx, int dy) { x += dx; y += dy; }
    }
    

    causes a compile-time error because it declares two move methods with the same signature. This is an error even though one of the declarations is abstract.

    So the "rule" is

    the name of the method and the number and types of formal parameters to the method

提交回复
热议问题