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)
-
Method 1: import oracle.sql.*; public class JClob { String tableName = null; // String primaryKey = null; // String primaryValue = null; // ...
-
1. Change the tile of web.xml from <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "ht...
-
While starting the server pass the IP address using the -b option. For eg: if you want to access the page using IP address, start the server...
No comments:
Post a Comment