Are there getattr, callable and other metaprogramming functions in java?

I am looking for some metaprogramming functions in Java, similar to Python getattr, hasattr, called, etc. If not, is there a good external library for this?

+4
source share
4 answers

As Eduardo noted, you can use reflection. Here's a Sun (Oracle, now) article about this:

http://java.sun.com/developer/technicalArticles/ALT/Reflection/

This should make you move in the right direction.

+1
source

Also the JavaBean spec dabbles specification in this area.

see java.beans.BeanInfo

There are also libraries like commons-beanutils, which are built on the basis of reflection, which tries to be more like meta-processing.

+1
source

Some of the best metaprogramming libraries take the form of alternative languages ​​that run on the JVM; for example, Groovy is a slightly simplified Java language with better metaprogramming support (among other features).

+1
source

In addition to reflection, you may be interested in AOP (for example, through AspectJ ), which allows before and after processing method calls, conversions, hooks, etc. different Java execution sequences.

It is not possible to intercept calls to methods that do not exist, since such code cannot be compiled.

0
source

Source: https://habr.com/ru/post/1344393/


All Articles