How do I call overloaded Java methods in Clojure.
- by Pat Wallace
For this example Java class:
package foo;
public class TestInterop
{ public String test(int i)
{ return "Test(int)"; }
public String test(Object i)
{ return "Test(Object)"; }
}
When I start Clojure and try to call the test(int) method, the test(Object) method is called instead, because Clojure automatically boxes the integer into a java.lang.Integer object.
How do I force Clojure to call the test(int) method?
user=> (.test (new foo.TestInterop) 10)
"Test(Object)"
I want to call methods like Component.add(Component comp, int index) in AWT, but instead keep calling add(Component comp, Object constraints), so the buttons on my toolbar always appear in the wrong order.