Skip to content

Commit a129b6e

Browse files
committed
Better generics
1 parent 78b86ce commit a129b6e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/main/java/org/apache/commons/cli/TypeHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,9 @@ public static URL createURL(final String string) throws ParseException {
168168
* @return The instance of {@code clazz} initialized with the value of {@code string}.
169169
* @throws ParseException if the value creation for the given class threw an exception.
170170
*/
171-
@SuppressWarnings("unchecked") // returned value will have type T because it is fixed by clazz
172171
public static <T> T createValue(final String string, final Class<T> clazz) throws ParseException {
173172
try {
174-
return (T) getConverter(clazz).apply(string);
173+
return getConverter(clazz).apply(string);
175174
} catch (final Throwable e) {
176175
throw ParseException.wrap(e);
177176
}
@@ -211,12 +210,14 @@ private static <T> T createValueUnchecked(final String string, final Class<T> cl
211210
/**
212211
* Gets the registered converter for the the Class, or {@link Converter#DEFAULT} if absent.
213212
*
213+
* @param <T> The Class parameter type.
214214
* @param clazz The Class to get the Converter for.
215215
* @return the registered converter if any, {@link Converter#DEFAULT} otherwise.
216216
* @since 1.7.0
217217
*/
218-
public static Converter<?, ?> getConverter(final Class<?> clazz) {
219-
return converterMap.getOrDefault(clazz, Converter.DEFAULT);
218+
@SuppressWarnings("unchecked") // returned value will have type T because it is fixed by clazz
219+
public static <T> Converter<T, ?> getConverter(final Class<T> clazz) {
220+
return (Converter<T, ?>) converterMap.getOrDefault(clazz, Converter.DEFAULT);
220221
}
221222

222223
/**

0 commit comments

Comments
 (0)