1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| public class Main {
public static void main(String[] args) { final Human bitch = new SpringBrother();
Human middleman = (Human)Proxy.newProxyInstance(bitch.getClass().getClassLoader(), bitch.getClass().getInterfaces(), new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if("sing".equals(method.getName())){ float money = (Float)args[0]; if(money>10000){ method.invoke(bitch, money/2); } } if("dance".equals(method.getName())){ float money = (Float)args[0]; if(money>20000){ method.invoke(bitch, money/2); } } return null; } }); middleman.sing(100000); middleman.dance(200000); }
}
|