出现的问题, 是参数不匹配或是出现空指针异常
Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.xxxx.design_pattern_example.dynamic_proxy.LogHandler.invoke(LogHandler.kt:23)
at com.sun.proxy.$Proxy0.lababa(Unknown Source)
at com.xxxx.design_pattern_example.dynamic_proxy.ProxyTestKt.main(ProxyTest.kt:30)
at com.xxxx.design_pattern_example.dynamic_proxy.ProxyTestKt.main(ProxyTest.kt)
解决问题:
是引入的invoke方法参数的问题
override fun invoke(proxy: Any, method: Method, args: Array<out Any>): Any? {
return null
}
同时在invoke方法中使用args参数时,需要使用引用值即使*args
method.invoke(xxxxImpl, *args)