How to access a non-static private field in java? -


i have non-static private field in package , want access package don't know how that. searched didn't find useful , other questions in site weren't exacatly question.

the way can via reflection. it's hack. ought finding way round it.

if need it, suggests other package has badly designed structure. if class you're trying manipulate 1 of own, should @ changing code.

if need , can't change other class, this:

field f = badclass.class.getdeclaredfield("privatefield"); f.setaccessible(true); f.set(badclassinstance, newvalue); 

probably best places start tutorial on reflection, , setaccessible method.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -