public < X > X invokeOnInstance ( Object instance , Object ... parameters ) throws IllegalArgumentException , SecurityException , IllegalAccessException , InvocationTargetException , NoSuchMethodException { final Map < Class < ? > , Method > methods = this . methods ; Method method = methods . get ( instance . getClass ( ) ) ; if ( method == null ) { // the same method may be written to the map twice, but that is ok // lookupMethod is very slow Method delegate = annotatedMethod . getJavaMember ( ) ; method = SecurityActions . lookupMethod ( instance . getClass ( ) , delegate . getName ( ) , delegate . getParameterTypes ( ) ) ; SecurityActions . ensureAccessible ( method ) ; synchronized ( this ) { final Map < Class < ? > , Method > newMethods = new HashMap < Class < ? > , Method > ( methods ) ; newMethods . put ( instance . getClass ( ) , method ) ; this . methods = WeldCollections . immutableMapView ( newMethods ) ; } } return cast ( method . invoke ( instance , parameters ) ) ; }
Invokes the method on the class of the passed instance not the declaring class . Useful with proxies