Last active
October 18, 2018 21:13
-
-
Save Mahoney/315c7dd5a10d4c6786ed19a1ecb49d40 to your computer and use it in GitHub Desktop.
Shows how Groovy allows delegating without exposing the encapsulated type
This file contains hidden or 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
| @CompileStatic | |
| class MyString { | |
| @Delegate | |
| private final String decorated | |
| MyString(String decorated) { | |
| this.decorated = decorated | |
| } | |
| } | |
| @CompileStatic | |
| class Test { | |
| static void main(String[] args) { | |
| def m = new MyString("blah") | |
| assert m.startsWith("bl") // compiles, passes | |
| assert !(m instanceof String) // passes | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment