Created
January 8, 2014 16:18
-
-
Save jimbaker/8319447 to your computer and use it in GitHub Desktop.
You can monkeypatch any imported Java class, just as if it's a Python class.
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
>>> from java.util.concurrent import ConcurrentHashMap as CHM | |
>>> def silly(self): return 2 * len(self) | |
... | |
>>> CHM.silly = silly | |
>>> x = CHM() | |
>>> x.silly() | |
0 | |
>>> x["a"] = 42 | |
>>> x.silly() | |
2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment