Dynamic proxy   动态代理

Befor talking about runtime weaving, let's take a look at Java dynamic proxy.

在说运行时织入之间,我们先看看java动态代理

电脑培训,计算机培训,平面设计培训,网页设计培训,美工培训,Web培训,Web前端开发培训

public class DynamicProxyTest {    public interface Vehicle
    {        void whistle();
    }    public static class Boat implements Vehicle
    {
        @Override        public void whistle()
        {
            System.out.println( "Boat whistle!" );
        }
    }    public static class VehicleHandler implements InvocationHandler
    {
        private Object proxied;

        public VehicleHandler(Object proxied )
        {
            this.proxied = proxied;
        }

        public Object invoke(Object proxy, Method method, Object[] args ) throws Throwable
        {
            checkVehicle();
            return meth
        
		

网友评论