020.java_标注和反射

标注:可以添加到程序代码的任何元素(包声明、类型声明、构造方法、方法、成员变量、参数),用来设置一些说明和解释。

反射(Reflection):是指程序可以访问、检测和修改本身状态或行为的一种能力。

代理

静态代理:

顾客委托中介公司找服装厂做衣服。

public interface ClothingFactory {
	void productClothing();//生产衣服的能力
}
public class LiNingCompany implements ClothingFactory{

	@Override
	public void productClothing() {
		// TODO Auto-generated method stub
		System.out.println("生产一批LiNing衣服");
	}

}
public class ProxyCompany implements ClothingFactory{

	ClothingFactory cf;
	public ProxyCompany(ClothingFactory cf) {
		// TODO Auto-generated constructor stub
		this.cf=cf;
	}
	@Override
	public void productClothing() {
		// TODO Auto-generated method stub
		System.out.println("收取中介费1000元");
		cf.productClothing();
	}

}
public class Customer {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ClothingFactory cf=new ProxyCompany(new LiNingCompany());
		cf.productClothing();
	}

}

运行结果:

收取中介费1000元
生产一批LiNing衣服




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值