可以使用java.lang.Class.getDeclaredMethods()方法列出java.lang.Math类的方法。
此方法返回一个数组,其中包含具有公共,私有,受保护和默认访问权限的所有Method对象。但是,不包括继承的方法。另外,getDeclaredMethods()
如果类或接口没有方法,或者在Class对象中表示原始类型,数组类或void ,则该方法返回零长度数组。
演示此的程序如下所示-
import java.lang.reflect.Method; public class Demo { public static void main(final String[] args) { final Method[] methods = Math.class.getDeclaredMethods(); System.out.println("Methods of java.lang.Math Class\n"); for (int i = 0; i < methods.length; i++) { System.out.println("The method is: " + methods[i]); } } }
输出结果
Methods of java.lang.Math Class The method is: public static int java.lang.Math.abs(int) The method is: public static double java.lang.Math.abs(double) The method is: public static float java.lang.Math.abs(float) The method is: public static long java.lang.Math.abs(long) The method is: public static double java.lang.Math.sin(double) The method is: public static double java.lang.Math.cos(double) The method is: public static double java.lang.Math.tan(double) The method is: public static double java.lang.Math.atan2(double,double) The method is: public static double java.lang.Math.sqrt(double) The method is: public static double java.lang.Math.log(double) The method is: public static double java.lang.Math.log10(double) The method is: public static double java.lang.Math.pow(double,double) The method is: public static double java.lang.Math.exp(double) The method is: public static long java.lang.Math.min(long,long) The method is: public static double java.lang.Math.min(double,double) The method is: public static float java.lang.Math.min(float,float) The method is: public static int java.lang.Math.min(int,int) The method is: public static double java.lang.Math.max(double,double) The method is: public static float java.lang.Math.max(float,float) The method is: public static long java.lang.Math.max(long,long) The method is: public static int java.lang.Math.max(int,int) The method is: public static long java.lang.Math.addExact(long,long) The method is: public static int java.lang.Math.addExact(int,int) The method is: public static long java.lang.Math.decrementExact(long) The method is: public static int java.lang.Math.decrementExact(int) The method is: public static long java.lang.Math.incrementExact(long) The method is: public static int java.lang.Math.incrementExact(int) The method is: public static int java.lang.Math.multiplyExact(int,int) The method is: public static long java.lang.Math.multiplyExact(long,long) The method is: public static long java.lang.Math.negateExact(long) The method is: public static int java.lang.Math.negateExact(int) The method is: public static int java.lang.Math.subtractExact(int,int) The method is: public static long java.lang.Math.subtractExact(long,long) The method is: public static double java.lang.Math.scalb(double,int) The method is: public static float java.lang.Math.scalb(float,int) The method is: public static float java.lang.Math.copySign(float,float) The method is: public static double java.lang.Math.copySign(double,double) The method is: public static int java.lang.Math.getExponent(double) The method is: public static int java.lang.Math.getExponent(float) The method is: public static double java.lang.Math.signum(double) The method is: public static float java.lang.Math.signum(float) The method is: public static double java.lang.Math.asin(double) The method is: public static double java.lang.Math.acos(double) The method is: public static double java.lang.Math.atan(double) The method is: public static double java.lang.Math.toRadians(double) The method is: public static double java.lang.Math.toDegrees(double) The method is: public static double java.lang.Math.cbrt(double) The method is: public static double java.lang.Math.IEEEremainder(double,double) The method is: public static double java.lang.Math.ceil(double) The method is: public static double java.lang.Math.floor(double) The method is: public static double java.lang.Math.rint(double) The method is: public static long java.lang.Math.round(double) The method is: public static int java.lang.Math.round(float) The method is: public static double java.lang.Math.random() The method is: public static int java.lang.Math.toIntExact(long) The method is: public static int java.lang.Math.floorDiv(int,int) The method is: public static long java.lang.Math.floorDiv(long,long) The method is: public static int java.lang.Math.floorMod(int,int) The method is: public static long java.lang.Math.floorMod(long,long) The method is: public static float java.lang.Math.ulp(float) The method is: public static double java.lang.Math.ulp(double) The method is: public static double java.lang.Math.sinh(double) The method is: public static double java.lang.Math.cosh(double) The method is: public static double java.lang.Math.tanh(double) The method is: public static double java.lang.Math.hypot(double,double) The method is: public static double java.lang.Math.expm1(double) The method is: public static double java.lang.Math.log1p(double) The method is: public static double java.lang.Math.nextAfter(double,double) The method is: public static float java.lang.Math.nextAfter(float,double) The method is: public static double java.lang.Math.nextUp(double) The method is: public static float java.lang.Math.nextUp(float) The method is: public static double java.lang.Math.nextDown(double) The method is: public static float java.lang.Math.nextDown(float) The method is: static double java.lang.Math.powerOfTwoD(int) The method is: static float java.lang.Math.powerOfTwoF(int)