Hi!

>> Hm, but even without the reader #=(..) syntax, there's some strangeness:
>>
>> --8<---------------cut here---------------start------------->8---
>> user> (. java.util.Date newInstance)
>> ; Evaluation aborted.
>> java.lang.NoSuchFieldException: newInstance
>>  [Thrown class java.lang.RuntimeException]
>> user> (. (identity java.util.Date) newInstance)
>> Reflection warning, NO_SOURCE_FILE:1 - reference to field newInstance can't 
>> be resolved.
>> #<Date Fri Sep 09 13:46:06 CEST 2011>
>> --8<---------------cut here---------------end--------------->8---
>>
>> Why do I have to use identity here?
>
> This used to be Clojure FAQ #1, when no other syntax was available.
> newInstance is an instance method of the class Class, so these days
> the best way to call it is (.newInstance java.util.Date).  If you want
> a static method of class Date, do something like (java.util.Date/UTC 1
> 2 3 4 5 6).  These are "modern" syntax.
>
> It's generally best not to use the older form (. foo bar) as it can be
> ambiguous.  But just so you know what's going on... If Clojure finds
> that foo is a class name, it assumes that bar is a static method or
> field of class bar.  When if can't find a foo in bar, it gives you the
> error above.  By wrapping foo in 'identity' you're making it clear to
> the compiler that the first arg to . is an expression not a class
> name, so it then looks for an instance method or field.

Thanks for the clarifications. :-)

Bye,
Tassilo

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to