K
- the type of the object that is the result of the conversionpublic 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:
Modifier and Type | Method and Description |
---|---|
K |
convert(String value)
Converts the specified command line argument value to some domain object.
|
Copyright © 1999-2021 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.