2

In Java, a varg function can be written like this:

public static void foo(int ... a) 
{
   // method body
} 

It gets called in Java like this:

<OBJ>.foo(1, 2, 3);

and it gets called in Clojure like this:

(<OBJ>/foo (int-array [1 2 3])

Is it possible to write foo in Clojure so that it gets called in Java as a varg function?

1 Answer 1

2

Unfortunately, there is no option to make Java-style varargs methods (that is, methods that accept arrays and have the VARARGS (0x80) bit set to true).

Instead, you can either make a function that accepts an array (and write a varargs wrapper around it in Java, if you need varargs) or make a Clojure's [&rest] function and .invoke() it with varargs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.