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 String[]
as argument
and returns void
.
What s the rule to compute the signature?
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 String[]
as argument
and returns void
.
What s the rule to compute the signature?
它总是带有一套括号的括号,其中一类是没有mas子或任何东西的,其次是封闭区之后的回报值的表示器。 它非常直截了当。
Here’s a table of type signatures:
Signature Java Type
Z boolean
B byte
C char
S short
I int
J long
F float
D double
V void
L fully-qualified-class ; fully-qualified-class
[ type type[]
Those last two mean that to name a class, you say, for example, Ljava/lang/Object;
, and to name an array of (for example) int
, you say [I
, and an array of array of int
is [[I
.
如果您想字面上compute signature的签名依据反省,其范围足够简单;只是使用上表,并附有处理物体和阵列的规则。
Justpr javap -s <class-name>
in the rafter contained the .class
file. 它将以100%的准确性告诉你。 无需对这些事情进行猜测。
快速搜索发现这一网页:
http://www.rgagnon.com/javadetails/java-0286.html。
There are two parts to the signature. The first part is enclosed within the parentheses and represents the method s arguments. The second portion follows the closing parenthesis and represents the return type. The mapping between the Java type and C type is
Type Chararacter boolean Z byte B char C double D float F int I long J object L short S void V array [
See here for some details.
从根本上说,它会给人带来一些好处,然后是回报。
http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#38649”rel=“nofollow” §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 isabstract
.
因此,“规则”是
http://www.ohchr.org。
是否有办法计算 Java类的签名方法?
您可以通过使用apache Commons-bcel,从方案上做到这一点。
package com.mageddo.coc.classes;
import java.io.IOException;
import com.sun.org.apache.bcel.internal.classfile.ClassParser;
public class JavaClass {
public static String structureAsText(Class<?> clazz) throws IOException {
final String classPath =
String.format(
"/%s.class",
clazz.getName()
.replace( . , / )
);
final ClassParser classParser = new ClassParser(
JavaClass.class.getResourceAsStream(classPath),
clazz.getSimpleName() + ".java"
);
return classParser.parse()
.toString();
}
public static void main(String[] args) throws IOException {
System.out.println(JavaClass.structureAsText(JavaClass.class));
}
}
产出
public class com.mageddo.coc.classes.JavaClass extends java.lang.Object
filename JavaClass.java
compiled from JavaClass.java
compiler version 52.0
access flags 33
constant pool 98 entries
ACC_SUPER flag true
Attribute(s):
SourceFile: JavaClass.java
3 methods:
public void <init>()
public static String structureAsText(Class clazz) [Signature: (Ljava/lang/Class<*>;)Ljava/lang/String;]
throws Exceptions: java.io.IOException
public static void main(String[] args)
throws Exceptions: java.io.IOException
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...