Looks good! I’m glad you’ve got general idea. As for questions, let’s start with the last one:
In jcall, can the first argument always be either an instance or the class itself?
In Java, there are 2 types of methods - instance methods and class (or static) methods. For example, if you have an instance of Integer
(e.g. number 58) and want to convert this specific instance to a string “58”, you call instance method toString
. Clearly, toString
depends on an instance value, not just its class.
Static methods are bound to classes instead. For example, if you want to parse string “58” to an integer, you can call static method Integer.parseInt()
. parseInt()
doesn’t depend on any specific instance of Integer
, rather it resides in Integer
“namespace”.
So if you have the following definition in Java:
class MyClass {
void foo() {...}
static void bar() {...}
}
you can call foo()
and bar
only like this:
mc = JMyClass(())
jcall(mc, "foo", Void, ())
jcall(JMyClass, "bar", Void, ())
you cannot call an instance method on a class (this method just won’t have enough information to run!) and you cannot call static methods on instance (although Java the language allows it, JVM itself doesn’t).
loadFromModelFile
is a static method, so the first argument to jcall
should definitely be JDependencyParser
, not its instance jdp
.
Why the NoSuchMethodError since loadFromModelFile is definitely a method of DependencyParser?
However, If we call loadFromModelFile
like this:
# WRONG!
jcall(JDependencyParser, "loadFromModelFile", JObject, (JString,), modelPath)
we will still get NoSuchMethodException
. Let’s see what methods are available:
julia> listmethods(JDependencyParser, "loadFromModelFile")
2-element Array{JavaCall.JavaObject{Symbol("java.lang.reflect.Method")},1}:
edu.stanford.nlp.parser.nndep.DependencyParser loadFromModelFile(java.lang.String)
edu.stanford.nlp.parser.nndep.DependencyParser loadFromModelFile(java.lang.String, java.util.Properties)
We are calling the first of these 2 methods, but provide JObject
as a return type while method signature requires (J)DependencyParser
! Fixing it gives us correct call:
jcall(JDependencyParser, "loadFromModelFile", JDependencyParser, (JString,), modelPath)