Safeafe property name for java bean

I am looking for alternatives to get the property name in a safe way.

For example, using lambdaj, I can do:

propertyName(on(Contract.class).getContractKey()) 

But this is a bit verbose, and the performance is low.

I hope that is created during assembly.

+6
source share
2 answers

Have you checked BeanUtils ? Obtaining a property name is usually not an unsafe part of a type; it accesses a property by name, which is usually unsafe.

0
source

If you are looking for solutions for building time, the simplest one might be generating code through reflection, but I don't know anything out of the box.

I'm not sure what you mean by accessing the property name in a safe way; you can create a static name / class map at build time and check for it.

It looks like you are trying to get the property name from a specific class, but there is nothing particularly interesting about this - you can handle it with normal reflection, since you must specify the class from which you can get properties from.

0
source

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


All Articles