rJava - .jcall calling issue: method with signatur

2019-06-18 08:57发布

问题:

I am trying to call a method in java class with rJava for a few days and I did not yet figure it out what I am doing wrong. Maybe someone here will have a some clues for me.

The situation looks like this:

  1. I load library and initializing an object (that's works fine):

    library(rJava)
    .jinit('C:/javatemp/worker.jar') 
    jobject <- .jnew("worker.concrete")
    
  2. I list methods and I get fine result:

    .jmethods(jobject)
    >  [1] "public java.util.List worker.concrete.lookup(java.lang.CharSequence)"  
    
  3. I am preparing input structure which also works fine:

    word <- .jnew("java/lang/String", "a word")
    input = .jcast(word, "java/lang/CharSequence", check = TRUE)
    
  4. However when I am trying to execute the method I get an error that such method does not exist...

    out = .jcall(jobject,"Ljava/util/List","lookup",input)
    > Error in .jcall(jobject, "Ljava/util/List", "lookup", input) : 
    method lookup with signature (Ljava/lang/CharSequence;)Ljava/util/List not found
    

Does anyone have an idea how to call such method?

回答1:

Sorry for answering an old question, but this has bugged me as well for some time. The answer is: ;

The format of type specification for non-primitive return types is Lpackage/subpackage/Type; - it has to end with a semicolon. So in the example above, you would need:

out = .jcall(jobject,"Ljava/util/List;","lookup",input)


标签: r rjava