-
-
Save LauJensen/352360 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
(ns joy.proxytest) | |
;;== evilbase | |
(gen-class | |
:name joy.proxytest.evilbase | |
:prefix "evilbase-" | |
:post-init ctor | |
:methods [[tragedy [] void]] | |
:impl-ns joy.proxytest) | |
(defn evilbase-ctor [this] | |
(println "evilctor before tragedy") | |
(.tragedy this) | |
(println "evilctor after tragedy")) | |
(defn evilbase-tragedy [this] | |
(println "this should never happen")) | |
;;== tryit using a proxy | |
(defn tryit [] | |
(let [p (proxy [joy.proxytest.evilbase] [] | |
(tragedy [] (println "my own tragedy")))] | |
; We wish that "my own tragedy" were printed above instead of | |
; "should never happen", but the ctor called .tragedy too early. | |
; Our proxy has caught up now: | |
(.tragedy p))) | |
;;== try it in another gen-class | |
(gen-class | |
:name joy.proxytest.hope | |
:prefix "hope-" | |
:extends joy.proxytest.evilbase | |
:impl-ns joy.proxytest) | |
(defn hope-tragedy [this] | |
(println "gen-class gives us the power")) | |
(defn tryit2 [] | |
(joy.proxytest.hope.)) | |
;;-- proxy does not behave as desired | |
; user=> (joy.proxytest/tryit) | |
; evilctor before tragedy | |
; this should never happen | |
; evilctor after tragedy | |
; my own tragedy | |
; nil | |
;;-- gen-class however gives us the power | |
; user=> (joy.proxytest/tryit2) | |
; evilctor before tragedy | |
; gen-class gives us the power | |
; evilctor after tragedy | |
; #<hope joy.proxytest.hope@5c061cd2> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment