Forums Register Login

Getting values from a method Using Reflection

+Pie Number of slices to send: Send
Hi,

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.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
return type of the method which am calling is String. field.get(obj) is giving illegalAccess Exception. Is there any limitation ? Please help.
+Pie Number of slices to send: Send
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?
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 637 times.
Similar Threads
Use of reflection API
Showing Serialized Object Graph on console using reflection
Java Reflection API
SpringAOP doubt
Java Reflection Problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:09:31.