Typesafe property name for a java bean
Asked Answered
S

2

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.

Stern answered 26/12, 2011 at 9:5 Comment(1)
is propertyName gone from the LambdaJ API? can't see it now..Repurchase
N
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.

Ness answered 28/12, 2011 at 14:22 Comment(0)
A
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.

Adara answered 28/12, 2011 at 14:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.