Whatever way you do it, the code will not look very beautiful. By its very nature, Java code that uses reflection tends to be quite verbose. The best you can do is put this code in a utility method, so ugliness and verbosity will be localized using one method and will not contain the rest of your code.
source share