Skip to content

Instantly share code, notes, and snippets.

@tmatinla
Last active December 14, 2015 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmatinla/5026427 to your computer and use it in GitHub Desktop.
Save tmatinla/5026427 to your computer and use it in GitHub Desktop.
Clojure proxy problem with protected method which is called from constructor
(ns test
(:import Test1))
(def test3 (proxy [Test1] []
(generateTest [] "test3")))
(println (.generateTest test3))
;=> test3
(println (.getTest test3))
;=> test1
// given a Java class like this:
public class Test1 {
private String test;
public Test1() {
this.test = generateTest();
}
protected String generateTest() {
return "test1";
}
public String getTest() {
return this.test;
}
private static class Test2 extends Test1 {
@Override
protected String generateTest() {
return "test2";
}
}
public static void main(String[] args) {
Test1 test1 = new Test1();
System.out.println(test1.getTest());
Test2 test2 = new Test2();
System.out.println(test2.getTest());
}
}
// running this produces output:
test1
test2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment