Last active
December 14, 2015 04:09
-
-
Save tmatinla/5026427 to your computer and use it in GitHub Desktop.
Clojure proxy problem with protected method which is called from constructor
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 test | |
(:import Test1)) | |
(def test3 (proxy [Test1] [] | |
(generateTest [] "test3"))) | |
(println (.generateTest test3)) | |
;=> test3 | |
(println (.getTest test3)) | |
;=> test1 |
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
// 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