[英]How to reflect classes like java.Math(I would like to extract parameters' types of functions like: Math.abs(), etc.)
I am trying to get the parameters' types(double, int) of the functions like Math.sin(double), Math.abs(int)我正在尝试获取 Math.sin(double)、Math.abs(int) 等函数的参数类型(double,int)
You can use getParameterTypes()
for publicly declared methods.您可以将
getParameterTypes()
用于公开声明的方法。 Something like this:像这样:
import java.lang.reflect.Method;
public class Main {
public static void main(String[] args) {
for (Method m : Math.class.getMethods()) {
Class<?>[] params = m.getParameterTypes();
for (Class<?> param : params) {
System.out.println(m.getName()+":"+param.getCanonicalName());
}
}
}
}
You can't chage the type of that function bec that are provided by Java and it's final class you can't chage the type你不能改变 Java 提供的那个函数的类型,它是你不能改变类型的最终类
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.