I have a super simple example where I have a list, a Java method and a call to this method. It looks like this:
#+name: animals
- dog
- cat
- guinea pig
- horse
#+name: does-contains-cat
#+begin_src java :results none
public boolean doesListContainsCat(List<String> list) {
return list.contains("cat");
}
#+end_src
#+begin_src java :results value :var animalList=animals
doesListContainsCat(animalList);
#+end_src
Output → error: cannot find symbol doesListContainsCat(animalList)
When evaluating the first block it creates a Java file with a class and a main method containing my method… I know it is the expected behaviour but it is not the result I want. By keeping it as simple as that (if possible) I want to be able to display a result when evaluating the second block.
My other tries:
#+name: doesListContainsCat
#+begin_src java :results none :var list='("")
return list.contains("cat");
#+end_src
#+begin_src java :results value :var list=animals doesListContainsCat
return doesListContainsCat(list);
#+end_src
Output → error: incompatible types: unexpected return value
or with a #+CALL header:
#+CALL: doesListContainsCat(list=animals)
Output → error: incompatible types: unexpected return value
I know it's because the return type of the main method in Java is void.
How to make it work (and keep it simple) so that I can define a Java method inside a source block, call it later using another source block and display the result?
:classnameheader argument to set a class name within which your function is defined. 2. Make your function static. 3. Access to you function from the second code block using dot notation.does-contains-catis encapsulated in a main method. @NickD Yes I have.