Interface PropertyRef<T,V>
- Type Parameters:
T- the bean typeV- the property type
- All Superinterfaces:
Function<T,V>, Serializable, com.vaadin.flow.function.SerializableFunction<T, V>, com.vaadin.flow.function.ValueProvider<T, V>
- All Known Implementing Classes:
PropertyRef.Nested
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface
public interface PropertyRef<T,V>
extends com.vaadin.flow.function.ValueProvider<T,V>
A reference to a bean property, expressed as a method reference to its getter,
instead of the property name as a String.
The main point is to get compile time safety and refactoring support for APIs that traditionally take property names as strings:
grid.setColumns(Person::getFirstName, Person::getLastName);
The property name is resolved from the method reference at runtime, using the
SerializedLambda that the JVM creates for serializable
lambdas (all Vaadin functional interfaces are serializable). The name resolution
is cached per method reference call site, see PropertyRefs.
Nested properties can be expressed by chaining:
grid.setColumns(PropertyRef.of(Person::getAddress).then(Address::getStreet));
Note that only actual method references work, a lambda expression like
p -> p.getFirstName() carries no property name and fails fast with an
IllegalArgumentException.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA nested property reference, created bythen(PropertyRef). -
Method Summary
Modifier and TypeMethodDescriptiondefault StringResolves the name of the property this reference points to.static <T,V> PropertyRef <T, V> of(PropertyRef<T, V> getterReference) Helper to give the compiler a target type for a method reference, needed to start a nested property path.default <U> PropertyRef<T, U> then(PropertyRef<V, U> nested) Creates a reference to a nested property.Methods inherited from interface com.vaadin.flow.function.ValueProvider
apply
-
Method Details
-
getPropertyName
Resolves the name of the property this reference points to. A getter namedgetFoo/isFoomaps tofoo, other method names (like record accessors) are used as such.- Returns:
- the property name, potentially a dot separated path for nested
references created with
then(PropertyRef)
-
then
Creates a reference to a nested property.- Type Parameters:
U- the type of the nested property- Parameters:
nested- the reference to the property in the type of this property- Returns:
- a reference whose property name is a dot separated path
-
of
Helper to give the compiler a target type for a method reference, needed to start a nested property path.- Type Parameters:
T- the bean typeV- the property type- Parameters:
getterReference- the method reference to the getter- Returns:
- the reference as such
-