How do I call overloaded Java methods in Clojure.
Posted
by Pat Wallace
on Stack Overflow
See other posts from Stack Overflow
or by Pat Wallace
Published on 2010-04-27T16:05:55Z
Indexed on
2010/04/28
2:23 UTC
Read the original article
Hit count: 388
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.
© Stack Overflow or respective owner