Re: Calling static methods on a variable holding a class

2009-07-08 Thread Nicolas Buduroi
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

Re: Calling static methods on a variable holding a class

2009-07-08 Thread Nicolas Buduroi
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

Re: Calling static methods on a variable holding a class

2009-07-07 Thread Stuart Sierra
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

Re: Calling static methods on a variable holding a class

2009-07-07 Thread Stephen C. Gilardi
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

Calling static methods on a variable holding a class

2009-07-06 Thread Nicolas Buduroi
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

Re: Calling static methods on a variable holding a class

2009-07-06 Thread Nicolas Buduroi
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

Re: Calling static methods on a variable holding a class

2009-07-06 Thread Adrian Cuthbertson
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

Re: Calling static methods on a variable holding a class

2009-07-06 Thread Adrian Cuthbertson
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