Forums Register Login
Getting values from a method Using Reflection

I have a class object and there are 2 getters in that with values. For some reason am getting classcastexception(weblogic class loader issue(not able to cast)). Is there any way I can get the values using reflection API or some other API. Please check.

I tried all the possibilities. Now only way is I have to get the values without type casting the class object.
I am not sure I totally follow your post but to just answer the question: Yes, you can call a method which returns a value from Reflection, and you can gain access to those returned values. See this part of the tutorial for details: http://docs.oracle.com/javase/tutorial/reflect/, and perhaps more specifically http://docs.oracle.com/javase/tutorial/reflect/member/methodInvocation.html.

But I think there might be more to your question: When do you get a ClassCastException? Can you show us some code that causes the ClassCastException and be more specific about precisely what you want to do?
return type of the method which am calling is String. field.get(obj) is giving illegalAccess Exception. Is there any limitation ? Please help.
This sounds like an example of the XY problem: you have some problem X (you're getting a ClassCastException), and you think that solution Y (reflection) will solve it. So you ask how to apply solution Y, without explaining what your problem X really is.

So, can you show us your code and explain exactly where you're getting a ClassCastException and what exactly the exception message is? Maybe we can then help you solve problem X, instead of giving you some tips for the wrong solution Y. Reflection is not magically going to help you bypass a ClassCastException.

In your last post you're mentioning IllegalAccessException. So is it ClassCastException or IllegalAccessException? Or are you having two problems at the same time?
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

This thread has been viewed 460 times.

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2018 05:02:15.