Created
January 19, 2012 20:18
-
-
Save sritchie/1642325 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defprotocol Connected | |
(isConnected [_]) | |
(getConnection [_])) | |
;; Putting the Class first succeeds... | |
(defn proxied-object [] | |
(proxy [Object user.Connected] [] | |
(isConnected [] "yes!") | |
(getConnection [] "connection.") | |
(toString [] "I am."))) | |
user> (proxied-object) | |
#<Object$Connected$f0455086 I am.> | |
user> (isConnected (proxied-object)) | |
"yes!" | |
user> (getConnection (proxied-object)) | |
"connection." | |
;;this won't compile: | |
(defn proxied-object [] | |
(proxy [user.Connected Object] [] | |
(isConnected [] "yes!") | |
(getConnection [] "connection.") | |
(toString [] "I am."))) | |
No message. | |
[Thrown class java.lang.NullPointerException] | |
Restarts: | |
0: [QUIT] Quit to the SLIME top level | |
Backtrace: | |
0: clojure.core$name.invoke(core.clj:1488) | |
1: clojure.core$proxy$fn__4887.invoke(core_proxy.clj:351) | |
2: clojure.core$proxy.doInvoke(core_proxy.clj:342) | |
3: clojure.lang.RestFn.invoke(RestFn.java:652) | |
4: clojure.lang.Var.invoke(Var.java:431) | |
5: clojure.lang.AFn.applyToHelper(AFn.java:202) | |
6: clojure.lang.Var.applyTo(Var.java:518) | |
7: clojure.lang.Compiler.macroexpand1(Compiler.java:6320) | |
8: clojure.lang.Compiler.analyzeSeq(Compiler.java:6395) | |
9: clojure.lang.Compiler.analyze(Compiler.java:6216) | |
10: clojure.lang.Compiler.analyze(Compiler.java:6177) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment