I have a scala object defined like the following:
package com.example
object Foo {
def bar(): String = "Interesting Result"
}
I know that I can call Foo$.MODULE$.bar() from Java if Foo is in the build and runtime classpath, but in my situation Foo is not in the build classpath and may or may not be configured in the runtime classpath.
From my Java code I’d like to use reflection to call bar() if it is available on the runtime classpath, otherwise I’ll fall back to a default implementation.
Is it possible to do this?
You can do it with code that looks something like this: