Enum Class ZeroArgumentNonVoidMethodPolicy
- All Implemented Interfaces:
Serializable
,Comparable<ZeroArgumentNonVoidMethodPolicy>
,Constable
BeansWrapper
, and therefore in DefaultObjectWrapper
.
This policy doesn't apply to methods that Java Beans introspector discovers as a property read method (which
typically look like getSomething()
, or isSomething()
). It's only applicable to methods like
something()
, including the component read methods of Java records.- Since:
- 2.3.33
- See Also:
BeansWrapperConfiguration.setDefaultZeroArgumentNonVoidMethodPolicy(ZeroArgumentNonVoidMethodPolicy)
,BeansWrapperConfiguration.setRecordZeroArgumentNonVoidMethodPolicy(ZeroArgumentNonVoidMethodPolicy)
,BeansWrapper.MethodAppearanceDecision.setMethodInsteadOfPropertyValueBeforeCall(boolean)
,MethodCallAwareTemplateHashModel
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionBothobj.m
, andobj.m()
gives back the value that them
Java method returns, and it's not possible to get the method itself.Onlyobj.m()
gives back the value in a template,obj.m
in a template just gives the method itself.obj.m
in a template gives back the value, and you can't get the method itself. -
Method Summary
Modifier and TypeMethodDescriptionReturns the enum constant of this class with the specified name.static ZeroArgumentNonVoidMethodPolicy[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
BOTH_METHOD_AND_PROPERTY_UNLESS_BEAN_PROPERTY_READ_METHOD
public static final ZeroArgumentNonVoidMethodPolicy BOTH_METHOD_AND_PROPERTY_UNLESS_BEAN_PROPERTY_READ_METHODBothobj.m
, andobj.m()
gives back the value that them
Java method returns, and it's not possible to get the method itself. But, it's not applicable for Java Bean property read methods (likeint getX()
), which remain just simple methods (because the Java Bean property is visible regardless of theZeroArgumentNonVoidMethodPolicy
, likeobj.x
, for which the Java Bean property read method isgetX()
).This is a parse-time trick that only works when the result of the dot operator (like
obj.m
), or of the square bracket key operator (likeobj["m"]
) is called immediately in a template (likeobj.m()
, or likeobj["m"]()
), and therefore the dot, or square bracket key operator knows that you will call the result of it. In such case, if the wrappedobj
implementsMethodCallAwareTemplateHashModel
, the operator will callMethodCallAwareTemplateHashModel.getBeforeMethodCall(String)
instead ofTemplateHashModel.get(String)
. Also note that at least in 2.3.33 it's only done if the method call has 0 arguments.The practical reason for this feature is that the convention of using
SomeType something()
instead ofSomeType getSomething()
spreads in the Java ecosystem (and is a standard in some other JVM languages), and thus we can't tell anymore ifSomeType something()
just reads a value, and hence should be accessed likeobj.something
, or it's more like an operation that has side effect, and therefore should be accessed likeobj.something()
. So with allowing both, the template author is free to decide which is the more fitting. Also, for accessing Java records components, the proper way isobj.something
, but before FreeMarker was aware of records (and hence that those methods are like property read methods), the only way that worked wasobj.something()
, so to be more backward compatible, we have to support both. -
METHOD_ONLY
Onlyobj.m()
gives back the value in a template,obj.m
in a template just gives the method itself. -
PROPERTY_ONLY_UNLESS_BEAN_PROPERTY_READ_METHOD
obj.m
in a template gives back the value, and you can't get the method itself. But, it's not applicable for Java Bean property read methods, which will remain normals methods, just like withBOTH_METHOD_AND_PROPERTY_UNLESS_BEAN_PROPERTY_READ_METHOD
.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-