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 u

Re: Calling static methods on a variable holding a class

2009-07-08 Thread Chouser
On Wed, Jul 8, 2009 at 10:23 AM, Nicolas Buduroi wrote: > >> 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 adva

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-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

Re: Calling static methods on a variable holding a class

2009-07-07 Thread Stuart Sierra
On Jul 6, 6:59 pm, Nicolas Buduroi 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 classes are not li

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

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 wrote: > > I've just figured out that the macro version in the allocate example > ca

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 wrote: > Hi, I needed

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 ByteBu

Re: Calling static methods on a variable holding a class

2008-10-16 Thread mb
Hi, On 16 Okt., 09:14, "V.Quixote" <[EMAIL PROTECTED]> wrote: > So after (def OpenGL GL11): > > user=> (.GL_QUADS GL11) > 7 > user=> (.GL_QUADS OpenGL) > java.lang.IllegalArgumentException: No matching field found: GL_QUADS > for class clojure.lang.Symbol (NO_SOURCE_FILE:0) > > Using (def OpenGL

Calling static methods on a variable holding a class

2008-10-16 Thread V.Quixote
So after (def OpenGL GL11): user=> (.GL_QUADS GL11) 7 user=> (.GL_QUADS OpenGL) java.lang.IllegalArgumentException: No matching field found: GL_QUADS for class clojure.lang.Symbol (NO_SOURCE_FILE:0) Using (def OpenGL 'GL11) doesn't work either, and using (defmacro OpenGL [] 'GL11) means I have t