java reflex_Java 反射reflex(1)

public interface AmericaDroid {

public abstract void fitting();

}

public interface ChinaDroid {

public abstract void say();

}

public interface GermanyDroid {

public abstract void song();

}

public class Droid implements GermanyDroid,AmericaDroid,ChinaDroid{

private int year;

private String country;

private String name;

public Droid() {

}

public Droid(int year) {

this.year = year;

}

public Droid(int year,String name,String country) {

this.year = year;

this.name=name;

this.country=country;

}

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

public String getCountry() {

return country;

}

public void setCountry(String country) {

this.country = country;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

@Override

public String toString() {

return "Droid [year=" + year + ", country=" + country + ", name=" + name + "]";

}

@Override

public void say() {

}

@Override

public void fitting() {

}

@Override

public void song() {

}

}

public class DroidTest {

/**

* @desc

 
 

* @author Weiliang Hu

* @date 2013-9-10

* @param args

*/

public static void main(String[] args) {

Droid mDroid = new Droid();

System.out.println("mDroid class Name:" + mDroid.getClass().getName().toString());

System.out.println("获取类名称:");

Class> test1 = null;

Class> test2 = null;

Class> test3 = null;

try {

test1 = Class.forName("cn.iworker.reflex.Droid");

} catch (ClassNotFoundException e) {

System.out.println("not found Droid Class");

e.printStackTrace();

}

test2 = new Droid().getClass();

test3 = Droid.class;

System.out.println("test1 class Name:" + test1.getName().toString());

System.out.println("test2 class Name:" + test2.getName().toString());

System.out.println("test3 class Name:" + test3.getName().toString());

Droid mDroid1 = null;

try {

mDroid1 = (Droid) test1.newInstance();

} catch (InstantiationException e) {

e.printStackTrace();

} catch (IllegalAccessException e) {

e.printStackTrace();

}

mDroid1.setCountry("America");

mDroid1.setYear(1956);

mDroid1.setName("fnic");

System.out.println(mDroid1.toString());

Constructor> cons[] = mDroid1.getClass().getConstructors();

try {

mDroid1 = (Droid) cons[0].newInstance(2003, "snick", "Japan");

System.out.println("mDroid3 name" + mDroid1.toString());

} catch (InstantiationException e) {

e.printStackTrace();

} catch (IllegalAccessException e) {

e.printStackTrace();

} catch (IllegalArgumentException e) {

e.printStackTrace();

} catch (InvocationTargetException e) {

e.printStackTrace();

}

for (int i = 0; i < cons.length; i++) {

System.out.println("Droid 的构造函数:" + cons[i]);

}

Class> inters[] = mDroid1.getClass().getInterfaces();

for (int i = 0; i < inters.length; i++) {

System.out.println("Droid 实现的接口----->>" + inters[i]);

}

}

}

mDroid class Name:cn.iworker.reflex.Droid

获取类名称:

test1 class Name:cn.iworker.reflex.Droid

test2 class Name:cn.iworker.reflex.Droid

test3 class Name:cn.iworker.reflex.Droid

Droid [year=1956, country=America, name=fnic]

mDroid3 nameDroid [year=2003, country=Japan, name=snick]

Droid 的构造函数:public cn.iworker.reflex.Droid(int,java.lang.String,java.lang.String)

Droid 的构造函数:public cn.iworker.reflex.Droid(int)

Droid 的构造函数:public cn.iworker.reflex.Droid()

Droid 实现的接口----->>interface cn.iworker.reflex.GermanyDroid

Droid 实现的接口----->>interface cn.iworker.reflex.AmericaDroid

Droid 实现的接口----->>interface cn.iworker.reflex.ChinaDroid

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值