Posted By

alun on 02/12/10


Tagged

access private


Versions (?)

get private field value


 / Published in: Groovy
 

Closure to help getting values of private fields

  1. def getFieldValue = { obj, fieldName ->
  2. def fields = obj.class.getDeclaredFields()
  3. Field field = fields.find { it.name == fieldName }
  4. field.setAccessible( true )
  5. return field.get( obj )
  6. }

Report this snippet  

You need to login to post a comment.