$'s in java class member names and set!

17 views
Skip to first unread message

Jon Seltzer

unread,
Sep 8, 2010, 1:23:48 AM9/8/10
to Clojure
Suppose you have a class projects.test.A:

package projects.test;

public class A
{
public A(){super();}
public boolean y;
public boolean $z;
}

and I want to use set to update both values:

user=> (def m (A.)) ; Create a ref m to new instance of A
#'user/m

user=> (set! (. m y) true) ; No problems updating y.
true

user=> (set! (. m $z) true)
java.lang.IllegalArgumentException: No matching field found:
_DOLLARSIGN_z for class projects.test.A
(NO_SOURCE_FILE:0)

Is there a special syntax for handling java members with $'s in their
names?


Sean Devlin

unread,
Sep 8, 2010, 11:05:09 PM9/8/10
to Clojure
Try using reflection to print out what the JVM thinks the field's name
is. This might help.

Jon Seltzer

unread,
Sep 8, 2010, 11:43:54 PM9/8/10
to Clojure
Yeah. I tried that but it gives what you expect:

Class A defined as follows:

package projects.test;
public class A
{
public boolean y;
public boolean $z;
}

REPL:

user=> (import '(projects.test A))
projects.test.A
user=> (def m (A.))
#'user/m
user=> (set! (. m y) true)
true
user=> (set! (. m $z) true)
java.lang.IllegalArgumentException: No matching field found:
_DOLLARSIGN_z for class projects.test.A
(NO_SOURCE_FILE:0)
user=> (def klass (.getClass m))
#'user/klass
user=> (def fields (.getFields klass))
#'user/fields
user=> (.getName (aget fields 0))
"y"
user=> (.getName (aget fields 1))
"$z"
user=>

Just so everyone knows this isn't a trumped up example. If I can make
this work then I can instantiate JavaFX classes directly without using
JavaFX reflection. I'm exploring a Clojure cover library for JavaFX.
Incidently, some of you might be interested in this:

http://steveonjava.com/javafx-your-way-building-javafx-applications-with-alternative-languages/

Stephen Chin will presenting a talk at JavaOne about using other JVM
languages to call JavaFX.
> > names?- Hide quoted text -
>
> - Show quoted text -

Michał Marczyk

unread,
Sep 9, 2010, 6:49:39 AM9/9/10
to clo...@googlegroups.com
That's probably due to a problem with clojure.core/munge I recently
reported on the Dev list [1] -- see a proposed patch attached to my
first e-mail in that thread. I notice there still hasn't been any
response to that issue... I think I'm just going to go ahead an open a
ticket for this tonight.

Sincerely,
Michał

[1] http://groups.google.com/group/clojure-dev/browse_thread/thread/9caab13eafa10f80

Michał Marczyk

unread,
Sep 9, 2010, 7:04:27 AM9/9/10
to clo...@googlegroups.com

Jon Seltzer

unread,
Sep 9, 2010, 8:29:57 AM9/9/10
to Clojure
I suspect $ is in munge because Rich and company may want to use it as
a special reader character. $'s used to access inner classes work
fine. I'd be fine with that as long as there's still a way to access
Java identifiers with dollar signs (perhaps a special macro).
> [1]http://groups.google.com/group/clojure-dev/browse_thread/thread/9caab...
Reply all
Reply to author
Forward
0 new messages