-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignature.java
More file actions
31 lines (29 loc) · 1.15 KB
/
Signature.java
File metadata and controls
31 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
public class Signature {
public static void main(String[] args) throws NoSuchMethodException, SecurityException{
System.out.println(getSignature(Signature.class.getDeclaredMethod("getSignature",Method.class)));
}
public static String getSignature(Method m){
String sig;
try {
Field gSig = Method.class.getDeclaredField("signature");
gSig.setAccessible(true);
sig = (String) gSig.get(m);
if(sig!=null) return sig;
} catch (IllegalAccessException | NoSuchFieldException e) {
// e.printStackTrace();
}
StringBuilder sb = new StringBuilder("(");
for(Class<?> c : m.getParameterTypes())
sb.append((sig=Array.newInstance(c, 0).toString())
.substring(1, sig.indexOf('@')));
return sb.append(')')
.append(
m.getReturnType()==void.class?"V":
(sig=Array.newInstance(m.getReturnType(), 0).toString()).substring(1, sig.indexOf('@'))
)
.toString();
}
}