If you know the method you wish to call, do you not know the class and can
thus call the static method directly?
Well that was the point of the question, that is if I have to call a
static method on a class we don't know in advance. I understand this
capability isn't that useful and is quite
Lets say you want to call static method foo of a class,
but you don't know which class -- you want this to be
specified at runtime in a parameter. Something like this:
(defn map-foo [cls coll]
(map cls/foo coll)) ; doesn't work
As mentioned by others, one approach is to use
On Jul 6, 6:59 pm, Nicolas Buduroi nbudu...@gmail.com wrote:
Hi, I needed to call a static method on a class stored in a var
yesterday and found that it was a little bit trickier than I initially
thought.
My first impression is that this is probably not the best way to go
about this. Java
On Jul 7, 2009, at 3:29 PM, Stuart Sierra wrote:
If you really don't know what the class is (for example, you get a
Class object returned by some library function) then you can use the
Java Reflection API to call the static method. See
http://java.sun.com/docs/books/tutorial/reflect/
If you
Hi, I needed to call a static method on a class stored in a var
yesterday and found that it was a little bit trickier than I initially
thought. There's three way of doing it, the two first are quite
straightforward and working ;-) e.g.:
(import '(java.nio ByteBuffer FloatBuffer))
(def foo
I've just figured out that the macro version in the allocate example
can't be used with local variables.
(let [foo ByteBuffer]
(allocate1 foo 1024))
throws java.lang.UnsupportedOperationException: Can't eval locals
(NO_SOURCE_FILE:94)
On Jul 6, 6:59 pm, Nicolas Buduroi nbudu...@gmail.com
You can call the static method directly on the class name;
(java.nio.ByteBuffer/allocate 1024)
or just (ByteBuffer/allocat 1024)
if it's imported.
Rgds, Adrian.
On Tue, Jul 7, 2009 at 2:16 AM, Nicolas Buduroi nbudu...@gmail.com wrote:
I've just figured out that the macro version in the
Hi Nicolas, sorry, that last post missed the second part, I meant to add;
If you know the method you wish to call, do you not know the class and can
thus call the static method directly?
-Adrian.
On Tue, Jul 7, 2009 at 5:21 AM, Adrian Cuthbertson
adrian.cuthbert...@gmail.com wrote:
You can