fields of inherited classes

23 views
Skip to first unread message

Sandeep Puri

unread,
Apr 11, 2008, 1:15:25 AM4/11/08
to Clojure
Hi all,
Quite new to clojure. Maybe I'm doing something wrong here. I was
trying to run a simple test of the jmonkey game libraries.

This is the simple java source:

public class HelloWorld extends SimpleGame{
public static void main(String[] args) {
HelloWorld app = new HelloWorld(); // Create Object
// Signal to show properties dialog
app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
app.start(); // Start the program
}
protected void simpleInitGame() {
// Make a box
Box b = new Box("Mybox", new Vector3f(0,0,0), new Vector3f(1,1,1));
rootNode.attachChild(b); // Put it in the scene graph
}
}

In clojure I have,

(def app (doto (proxy [SimpleGame] []
(simpleInitGame []
(let [rt (. this rootNode)]
(. rt (attachChild
(new Box
"mybox"
(new Vector3f 0 0 0)
(new Vector3f 1 1
1)))))))
(setDialogBehaviour 2)))
(. app (start))

I get java.lang.IllegalArgumentException: No matching field found:
rootNode
at clojure.lang.Reflector.getInstanceField(Reflector.java:189)

rootNode should be inherited from SimpleGame (which actually inherits
from another class BaseSimpleGame.

Any help in pointing me in the right direction would be appreciated.

Christophe Grand

unread,
Apr 11, 2008, 1:55:00 AM4/11/08
to Clojure
Don't know how to work around but the missing information is that
rootNode is protected.

Rich Hickey

unread,
Apr 11, 2008, 9:01:02 AM4/11/08
to Clojure
As it says in the docs for proxy, you can't access protected members
from a proxy.

You best bet is to create a stub class in Java that derives from
SimpleGame and exposes any protected members you want to access via
public methods. Then in Clojure proxy that stub.

Rich

Sandeep Puri

unread,
Apr 11, 2008, 10:44:17 AM4/11/08
to Clojure
Thanks. I must've missed the part about protected members.
More reading.
This is great. Quick and awesome feedback.
-Sandeep
Reply all
Reply to author
Forward
0 new messages