String.
The annotated class must satisfy the following contracts:
- Parser: It must have a
public staticfactory method (named byparseMethodName()) that accepts a singleCharSequenceparameter, returns the enclosing type, and does not throw any checked exception. An invalid input should raise anIllegalArgumentException(or a subclass thereof). - Formatter: It must have a
publicnon-static, no-arg method (named byformatMethodName()) that returns aStringand does not throw any checked exception. - Short formatter (optional): When
hasShortFormat()istrue, the class must also have apublicnon-static, no-arg method (named byshortFormatMethodName()) that returns aStringand does not throw any checked exception.
The string representation should be consistent: formatting an object to a string and parsing that string back should yield an equal object.
- Author:
- Philippe Charles
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionName of the instance method used to format the object as aString.booleanWhether to enforce the presence of a short format method.Name of the static factory method used to parse aCharSequenceinto an instance of the annotated class.Name of the short format method used to produce an abbreviated string representation.
-
Element Details
-
parseMethodName
String parseMethodNameName of the static factory method used to parse aCharSequenceinto an instance of the annotated class.The method must be
public static, accept a singleCharSequenceparameter, return the annotated type, and not throw any checked exception.- Returns:
- the parse method name; defaults to
"parse"
- Default:
"parse"
-
formatMethodName
String formatMethodNameName of the instance method used to format the object as aString.The method must be
public, non-static, accept no parameters, return aString, and not throw any checked exception.- Returns:
- the format method name; defaults to
"toString"
- Default:
"toString"
-
hasShortFormat
boolean hasShortFormatWhether to enforce the presence of a short format method.When
true, the annotated class must also have apublic, non-static, no-arg method namedshortFormatMethodName()that returns aStringand does not throw any checked exception. The method may be inherited from a parent class.- Returns:
trueto enforce a short format method; defaults tofalse
- Default:
false
-
shortFormatMethodName
String shortFormatMethodNameName of the short format method used to produce an abbreviated string representation.This property is only effective when
hasShortFormat()istrue. The referenced method must bepublic, non-static, accept no parameters, return aString, and not throw any checked exception. The method may be inherited from a parent class.- Returns:
- the short format method name; defaults to
"toShortString"
- Default:
"toShortString"
-