java.lang.reflect.Method 类提供了访问方法的修饰符,返回类型,方法参数,注解,和可能抛也的异常的API.也可以调用方法.:
获取方法类型信息:
如何来列举申明在类中的方法,以及如何获取其类型信息.
一个方法的申明包括方法名,修饰符,参数,返回类型,以及可能抛也的异常.我们可能通过java.lang.reflect.Method来获取.如下示例:
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import static java.lang.System.out;
public class MethodSpy {
private static final String fmt = "%24s: %s%n";
<E extends RuntimeException> void genericThrow() throws E {}
private int get(int x,int y,double z) {
return 0;
}
public static void main(String... args) {
try {
Class<?> c = Class.forName(args[0]);
Method[] allMethods = c.getDeclaredMethods();
for(Method m : allMethods) {
if(!m.getName().equals(args[1])) {
continue;
}
out.format("%s%n",m.toGenericString());
out.format(fmt, "ReturnType",m.getReturnType());
out.format(fmt, "GenericReturnType",m.getGenericReturnType());
Class<?> [] pType = m.getParameterTypes();
Type[] gpType = m.getGenericParameterTypes();
for(int i = 0; i < pType.length;i++) {
out.format(fmt,"ParameterType",pType[i]);
out.format(fmt,"genericParameterType",gpType[i]);
}
Class<?>[] xType = m.getExceptionTypes();
Type[] gxType = m.getGenericExceptionTypes();
for(int i = 0;i < xType.length;i++) {
out.format(fmt,"ExceptionType",xType[i]);
out.format(fmt,"GenericExceptionType",gxType[i]);
}
} //for
} catch(ClassNotFoundException x) {
x.printStackTrace();
}
} //main
}//class
分享到:
相关推荐
Level Set Methods(水平集方法)和Dynamic Implicit Surfaces(动态隐式曲面)是计算几何中的重要概念,广泛应用于图像处理、计算物理等领域。Level Set Methods由Stanley Osher和Ronald Fedkiw等人提出,并在Osher...
Included are advanced methods in computational fluid dynamics, like direct and large-eddy simulation of turbulence, multigrid methods, parallel computing, moving grids, structured, block-structured ...
Title: Applied Numerical Methods with MATLAB for Engineers and Scientists, 4th Edition Author: Steven Chapra Length: 720 pages Edition: 4 Language: English Publisher: McGraw-Hill Education Publication...
Numerical Methods: Using MATLAB By 作者: George Lindfield – John Penny ISBN-10 书号: 0128122560 ISBN-13 书号: 9780128122563 Edition 版本: 4 出版日期: 2018-10-30 pages 页数: (608 ) $99.95 The fourth ...
‘Bayesian Methods for Statistical Analysis’ is a book on statistical methods for analysing a wide variety of data. The book consists of 12 chapters, starting with basic concepts and covering ...
本文件提到的书《核方法与机器学习》(Kernel Methods and Machine Learning)为读者提供了关于核学习理论的基本原理,强调了统计和代数原则的结合。书中详细介绍了超过30个重要的定理,这些定理不仅为核学习模型的...
本书《Mathematical Methods for Physicists by G.Arfken.pdf》是第六版,其内容主要涵盖了物理学中所需应用的数学方法,作者是George B. Arfken和Hans J. Weber,分别来自迈阿密大学和弗吉尼亚大学。这本书在学术上...
《Statistical Methods for Reliability Data》是一本深入探讨可靠性数据分析的经典著作,该书的数据集提供了丰富的实例,便于读者理解和应用书中的统计方法。这个压缩包包含的资源是这本书的重要补充,帮助读者在...
Mathematical Methods of Statistics - Cramer 统计数学奠基性著作 In this classic of statistical mathematical theory, Harald Cramér joins the two major lines of development in the field: while British ...
从给定的文件内容中,我们可以提炼出关于非线性分析的知识点,特别是围绕着Kung-Ching Chang的著作《Methods in Nonlinear Analysis》(2005年)的信息。以下是详细的介绍: 首先,《Methods in Nonlinear Analysis...
《Numerical Methods Using MATLAB_Mathews_4th》是一本专为使用MATLAB进行数值计算而编写的经典教材,由John C. Mathews和 Kurtis D. Fink合作撰写,现在已经更新到了第四版。这本书主要关注如何利用MATLAB的强大...
Level set methods and fast marching methods: evolving interfaces in computational geometry, fluid mechanics, computer vision, and materials science[M]. Cambridge university press, 1999.
《Mathematical Methods for Physicists》是一本广泛被物理学家、工程师以及科学家所使用的经典教材,旨在为学习者提供一系列全面且深入的数学工具和技术。本书由George B. Arfken、Hans J. Weber以及Frank E. ...
本书标题《Numerical Methods for Stochastic Computations-A Spectral Method Approach》意味着内容将集中在随机计算中的数值方法,并采用谱方法作为主要的技术途径。谱方法通常在求解偏微分方程或具有随机参数的...
首先,标题 "DATA MINING METHODS and APPLICATIONS" 提示我们这本书主要聚焦于数据挖掘方法以及这些方法在实际场景中的应用。数据挖掘是指从大量的、不完全的、有噪声的、模糊的实际数据中,提取隐含在其中的、人们...
文档中提到的系列丛书涵盖了计算电磁学的各个方面,其中 "Field Computation by Moment Methods" 由 R.F.Harrington 所著,详细讲解了利用矩量法计算电磁场问题的方法。矩量法通过将连续的电磁场问题转化为离散的...
Ensemble Methods_Foundations and Algorithms.pdf;Ensemble Methods_Foundations and Algorithms.pdf
《Statistical Analysis of Network Data: Methods and Models》是由Edmund R. Kolaczyk于2009年出版的一本专业书籍,它深入探讨了如何使用统计学工具来理解和解析复杂的网络数据。这本书旨在为研究人员和学生提供一...