獲取類位元組碼檔案 .class 檔案的3種方法
阿新 • • 發佈:2019-01-27
package fanxin;
public class RefectDemo {
public static void main(String[] args) throws ClassNotFoundException{
getClassObj_1() ;
}
public static void getClassObj_1()
{
Person p=new Person();
Class c=p.getClass();
Person p1=new Person();
Class c1=p1.getClass();
System.out.println(c==c1);//true
}
public static void getClassObj_2()
{
Class c=Person.class;
}
public static void getClassObj_3() throws ClassNotFoundException
{
String classname="fanxin.Person";
Class c=Class.forName(classname);
System.out.println(c);
}
}
public class RefectDemo {
public static void main(String[] args) throws ClassNotFoundException{
getClassObj_1() ;
}
public static void getClassObj_1()
{
Person p=new Person();
Class c=p.getClass();
Person p1=new Person();
Class c1=p1.getClass();
System.out.println(c==c1);//true
}
public static void getClassObj_2()
{
Class c=Person.class;
}
public static void getClassObj_3() throws ClassNotFoundException
{
String classname="fanxin.Person";
Class c=Class.forName(classname);
System.out.println(c);
}
}