Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

java - How to fetch variables from a third party class without in-build methods

I am using a third party Java class to fetch an instance of the class. However, only a few variables can be fetched using respective methods. I can see other variables when I print the instance and I would like to fetch some of them. Is there a Java way to do that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As it was pointed out in comment. You can refer to this answer. And use reflection in this way:

Field f = thirdPartyObject.getClass().getDeclaredField("hiddenString"); //NoSuchFieldException
f.setAccessible(true);
String hiddenString = (String) f.get(thirdPartyObject); //IllegalAccessException

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...