Package org.joda.convert
Class ReflectionStringConverter<T>
- java.lang.Object
-
- org.joda.convert.ReflectionStringConverter<T>
-
- Type Parameters:
T
- the type of the converter
- All Implemented Interfaces:
FromStringConverter<T>
,StringConverter<T>
,ToStringConverter<T>
,TypedStringConverter<T>
- Direct Known Subclasses:
MethodConstructorStringConverter
,MethodsStringConverter
abstract class ReflectionStringConverter<T> extends java.lang.Object implements TypedStringConverter<T>
Conversion to and from a string using reflection.The toString method must meet the following signature:
String anyName()
on Class T.ReflectionStringConverter is abstract, but all known implementations are thread-safe and immutable.
-
-
Constructor Summary
Constructors Constructor Description ReflectionStringConverter(java.lang.Class<T> cls, java.lang.reflect.Method toString)
Creates an instance using two methods.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
convertToString(T object)
Converts the object to aString
.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.joda.convert.FromStringConverter
convertFromString
-
Methods inherited from interface org.joda.convert.TypedStringConverter
getEffectiveType
-
-
-
-
Field Detail
-
cls
private final java.lang.Class<T> cls
The converted class.
-
toString
private final java.lang.reflect.Method toString
Conversion to a string.
-
-
Constructor Detail
-
ReflectionStringConverter
ReflectionStringConverter(java.lang.Class<T> cls, java.lang.reflect.Method toString)
Creates an instance using two methods.- Parameters:
cls
- the class this converts for, not nulltoString
- the toString method, not null- Throws:
java.lang.RuntimeException
- (or subclass) if the method signatures are invalid
-
-
Method Detail
-
convertToString
public java.lang.String convertToString(T object)
Converts the object to aString
.- Specified by:
convertToString
in interfaceToStringConverter<T>
- Parameters:
object
- the object to convert, not null- Returns:
- the converted string, may be null but generally not
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-