Search code examples
javanashorn

Is the a default method in java Nashorn which is invoked when the actual method is not present?


I'm looking for something in the Nashorn javascript engine in Java which would call a generic method as a fallback when the actual method cannot be found.

It should be something similar to groovy's methodMissing or invokeMethod features.

Is there anything like that?

I tried with java Proxy, but the InvocationHandler would be called only for methods in the interface... while I would want something like an InvocationHandler which should be called for any method.


Solution

  • Have a look at the noSuchMethod feature documented here. There is also a noSuchProperty hook for doing the same with properties and variables.