@ Benchmark public ExampleClass benchmarkJavassist ( ) throws Exception { ProxyFactory proxyFactory = new ProxyFactory ( ) { protected ClassLoader getClassLoader ( ) { return newClassLoader ( ) ; } } ; proxyFactory . setUseCache ( false ) ; proxyFactory . setUseWriteReplace ( false ) ; proxyFactory . setSuperclass ( baseClass ) ; proxyFactory . setFilter ( new MethodFilter ( ) { public boolean isHandled ( Method method ) { return method . getDeclaringClass ( ) == baseClass ; } } ) ; @ SuppressWarnings ( "unchecked" ) Object instance = proxyFactory . createClass ( ) . getDeclaredConstructor ( ) . newInstance ( ) ; ( ( javassist . util . proxy . Proxy ) instance ) . setHandler ( new MethodHandler ( ) { public Object invoke ( Object self , Method thisMethod , Method proceed , Object [ ] args ) throws Throwable { return proceed . invoke ( self , args ) ; } } ) ; return ( ExampleClass ) instance ; }
Performs a benchmark of a class extension using javassist proxies .