On Monday, March 20, 2017 at 4:59:33 PM UTC-4, Colin Fleming wrote:
>
> Object doesn't have a getName() method.
>
> This doc is confusing - as Phill comments above, this is calling the
> getName() method on an instance of Class. In Clojure, a bare classname
> (String, ArrayList or whatever) resolves to the class itself if it has been
> imported (i.e. what would be String.class in Java). The doc is confusing
> because (.instanceMember Classname args*) is really just a special case
> of (.instanceMember instance args*), where "instance" refers to an instance
> of a Class object. I'm not sure why that doc makes that distinction, it
> doesn't seem useful to me.
>
Oh. I see. `SomeClass` is an instance of java.lang.Class.
user=> (. (class String) getName)
"java.lang.Class"
Though, the second code block down at
<https://clojure.org/reference/java_interop> says:
(.instanceMember Classname args*) ==>
(. (identity Classname) instanceMember args*)
However, I don't understand why this works:
user=> (. (identity String) getName)
"java.lang.String"
since
user=> (= String (identity String))
true
and this fails:
user=> (. String getName)
CompilerException java.lang.NoSuchFieldException: getName,
compiling:(/tmp/form-init2724986764275224936.clj:1:1)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.