Created
February 2, 2022 02:05
-
-
Save UnconventionalMindset/da249f200ddb5d38c13a63ed3d3acb1b to your computer and use it in GitHub Desktop.
Get Private field in Scala for debugging purposes
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
def privateField[A](obj: AnyRef, fieldName: String): A = { | |
val f = obj.getClass.getDeclaredField(fieldName) | |
f.setAccessible(true) | |
f.get(obj).asInstanceOf[A] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment