Interface CommandLine.ITypeConverter<K>
- Type Parameters:
K- the type of the object that is the result of the conversion
- All Known Implementing Classes:
CommandLine.BuiltIn.BigDecimalConverter, CommandLine.BuiltIn.BigIntegerConverter, CommandLine.BuiltIn.BooleanConverter, CommandLine.BuiltIn.ByteConverter, CommandLine.BuiltIn.CharacterConverter, CommandLine.BuiltIn.CharSequenceConverter, CommandLine.BuiltIn.CharsetConverter, CommandLine.BuiltIn.DoubleConverter, CommandLine.BuiltIn.FileConverter, CommandLine.BuiltIn.FloatConverter, CommandLine.BuiltIn.InetAddressConverter, CommandLine.BuiltIn.IntegerConverter, CommandLine.BuiltIn.ISO8601DateConverter, CommandLine.BuiltIn.ISO8601TimeConverter, CommandLine.BuiltIn.LongConverter, CommandLine.BuiltIn.PathConverter, CommandLine.BuiltIn.PatternConverter, CommandLine.BuiltIn.ShortConverter, CommandLine.BuiltIn.StringBuilderConverter, CommandLine.BuiltIn.StringConverter, CommandLine.BuiltIn.URIConverter, CommandLine.BuiltIn.URLConverter, CommandLine.BuiltIn.UUIDConverter
- Enclosing class:
CommandLine
public static interface CommandLine.ITypeConverter<K>
When parsing command line arguments and initializing
fields annotated with @Option or @Parameters,
String values can be converted to any type for which a ITypeConverter is registered.
This interface defines the contract for classes that know how to convert a String into some domain object.
Custom converters can be registered with the CommandLine.registerConverter(Class, ITypeConverter) method.
Java 8 lambdas make it easy to register custom type converters:
commandLine.registerConverter(java.nio.file.Path.class, s -> java.nio.file.Paths.get(s)); commandLine.registerConverter(java.time.Duration.class, s -> java.time.Duration.parse(s));
Built-in type converters are pre-registered for the following java 1.5 types:
- all primitive types
- all primitive wrapper types: Boolean, Byte, Character, Double, Float, Integer, Long, Short
- any enum
- java.io.File
- java.math.BigDecimal
- java.math.BigInteger
- java.net.InetAddress
- java.net.URI
- java.net.URL
- java.nio.charset.Charset
- java.sql.Time
- java.util.Date
- java.util.UUID
- java.util.regex.Pattern
- StringBuilder
- CharSequence
- String
-
Method Summary
-
Method Details
-
convert
-