9

I'm looking for alternatives to get a property name in a type safe way.

For example, using lambdaj, I can do:

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

But this is a bit verbose and the performance is not great.

I'm hoping for something that is generated during build.

Mario Fusco
  • 13,548
  • 3
  • 28
  • 37
IttayD
  • 28,271
  • 28
  • 124
  • 178

2 Answers2

0

Have you checked out BeanUtils? Getting the name of the property is usually not the type-unsafe part, it's accessing a property by name that tends to be type unsafe.

Pace
  • 41,875
  • 13
  • 113
  • 156
0

If you're looking for build-time solutions, the easiest may be code generation via reflection, but I know of nothing out-of-the-box.

I'm not sure what you mean by accessing the property name in a type-safe way, though; you could create a static name/classname map at build-time and check against that.

It looks more like you're trying to get the property name from a specific class, but there's nothing particularly interesting about that--that can be handled via normal reflection, since you must specify the class from which to get properties from.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302