public static void main(String[] args) {
// exTest();
try {
int result = div(10, 0);
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
private static int div(int num1, int num2) throws Exception {
if (num2 == 0)
throw new ArithmeticException("除数不能为0");
return num1 / num2;
}
private static class MyHandler extends Handler{
private final WeakReference<MainActivity> weakReference;
public MyHandler(MainActivity mainActivity){
weakReference = new WeakReference<MainActivity>(mainActivity);
}
@Override
public void handleMessage(Message msg) {
MainActivity mainActivity = weakReference.get();
if(mainActivity!=null){
switch (msg.what){
case LOAD_SUCESS:
mainActivity.iv.setImageBitmap((Bitmap) msg.obj);
break;
}
}
}
}
//静态代码
//代理设计模式
public class Test11{
public static void main(String[] args){
SuperMan man = new SuperMan();
Proxy proxy = new Proxy(man);
proxy.shopping();
}
}
interface Subject{//主题
public void shopping();
}
//被代理人
class SuperMan implements Subject{
private String name;
public void shopping(){
//在买 之前要做大量的评估工作
//......
System.out.println("为媳妇从网络上购买进口化妆品,老贵了");
}
}
//代理人
class Proxy implements Subject{
private Subject target;//被代理人
public Proxy(Subject target){
this.target = target;
}
//实现接口的方法
public void shopping(){
//代购之前要做的事情
System.out.println("做大量的商品专业评估");
target.shopping();//被代理人真正的业务
//代购之后要做的事情
System.out.println("代购之后的客户满意度调查");
}
}