import java.lang.reflect.*;
/**
* 获取指定CLASS内的信息(方法,包)
*/
public class ClassInfo {
public ClassInfo() {
}
public static void main(String[] args) throws Exception {
String fullClassName;
if (args.length != 1) {
fullClassName = "java.lang.String";
} else {
fullClassName = args[0];
}
Class cls = Class.forName(fullClassName);
// (1.) 创建实例
Object o = cls.newInstance();
// (2.) 取得package名
Package pack = cls.getPackage();
String packageName = pack.getName();
System.out.println("package: " + packageName);
System.out.println();
// (3.) 取得类名
String className = cls.getName();
System.out.println("class name: " + className);
System.out.println();
// (4.) 取成员变量名
Field[] fields = cls.getFields();
int i;
System.out.println("成员变量");
for (i = 0; i < fields.length; i++) {
System.out.println(" " + fields[i].toString());
}
System.out.println();
// (5.) 取得成员方法
Method[] methods = cls.getMethods();
System.out.println("成员方法");
for (i = 0; i < methods.length; i++) {
System.out.println(" " + methods[i].toString());
}
}
}
This blogger is recording some code samples,technical skill of java,.Net,javascript, css, html for myself use. All articles are coming from my own experience and my collections which are from internet world. If you find any material have copy right issue please leave a comment to me. I will delete it immediately. These articles are writing in English or Chinese. Hope these information can help other technical guys. Thanks for reading.
Subscribe to:
Post Comments (Atom)
-
If you get "This page calls for XML namespace http://richfaces.org/a4j declared with prefix a4j but no taglibrary exists for that names...
-
Method 1: import oracle.sql.*; public class JClob { String tableName = null; // String primaryKey = null; // String primaryValue = null; // ...
-
1.HTTP-binding(ServiceMix) 1.4 各组件间传递消息流的过程如下: 1. HttpClient : Http 客户端运行一个独立的 Java 客户端程序,通过其中的 URLConnection 类连接到 http://...
No comments:
Post a Comment