Welcome! Please see the About page for a little more info on how this works.

0 votes
in Java Interop by

I’m a newbie to Clojure. I want to call a Java method which is overloaded in Java, one has no parameter and the other has one parameter. I want to call the method with no parameter, but Clojure calls the method with one parameter and raise an IllegalArgumentException.

How can I call the Java method with no parameter from Clojure?

1 Answer

+1 vote
by
user=> (vec (.getBytes "ᵶ" "latin1"))
[63]
user=> (vec (.getBytes "ᵶ"))
[-31 -75 -74]
user=>

If you don't pass an argument then clojure will call the one that doesn't take an argument.

by
Thanks. But, in my case, unfortunately a method call didn't select the correct method. I think those methods are defined in a interface. I had called with [] as a parameter for dummy and it worked.
by
the jvm is very strict about parameter count.

you cannot call a method with the wrong number of arguments, so if you added a parameter and now it works, that means you are calling a different method (the number of arguments two a method is part of what identifies a method).

There are other things that play into method selection, like if the method with the correct number of arguments is not visible (is not public).
...