Skip to content

Instantly share code, notes, and snippets.

@jimbaker
Created January 8, 2014 16:18
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 jimbaker/8319447 to your computer and use it in GitHub Desktop.
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.
>>> 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