Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Reflection Utility

Is there a utility to get a property which isnt prefixed by get from an object using reflection similar to BeanUtils? e.g. if I specify "hashCode" and I want to get the object.hashCode() value.

Thanks.

like image 934
DD. Avatar asked Dec 20 '25 08:12

DD.


2 Answers

You can call hashCode() on every Object. You don't need reflection for this.

Otherwise, you can use the standard reflection classes - java.lang.Class and its method getMethod(..) which returns java.lang.reflect.Method.

like image 185
Bozho Avatar answered Dec 22 '25 22:12

Bozho


The java reflection API allows you to access any property on a given instance of a class, including private variables.

Reflection is a powerful tool that allows you to do many things, including instantiating objects with private constructors.

Here is a decent tutorial for reflection that a quick google search turned up.

http://tutorials.jenkov.com/java-reflection/index.html

like image 42
thattmatt Avatar answered Dec 22 '25 22:12

thattmatt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!