8

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
  • 12,410
  • 3
  • 24
  • 36
IttayD
  • 25,561
  • 25
  • 109
  • 173

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
  • 33,215
  • 10
  • 99
  • 130
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
  • 152,765
  • 23
  • 240
  • 286