This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new a129b6e  Better generics
a129b6e is described below

commit a129b6e948d4606bcf931e38ef77889236f91d60
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sun Apr 7 11:38:11 2024 -0400

    Better generics
---
 src/main/java/org/apache/commons/cli/TypeHandler.java | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/cli/TypeHandler.java 
b/src/main/java/org/apache/commons/cli/TypeHandler.java
index dfaed36..316556e 100644
--- a/src/main/java/org/apache/commons/cli/TypeHandler.java
+++ b/src/main/java/org/apache/commons/cli/TypeHandler.java
@@ -168,10 +168,9 @@ public class TypeHandler {
      * @return The instance of {@code clazz} initialized with the value of 
{@code string}.
      * @throws ParseException if the value creation for the given class threw 
an exception.
      */
-    @SuppressWarnings("unchecked") // returned value will have type T because 
it is fixed by clazz
     public static <T> T createValue(final String string, final Class<T> clazz) 
throws ParseException {
         try {
-            return (T) getConverter(clazz).apply(string);
+            return getConverter(clazz).apply(string);
         } catch (final Throwable e) {
             throw ParseException.wrap(e);
         }
@@ -211,12 +210,14 @@ public class TypeHandler {
     /**
      * Gets the registered converter for the the Class, or {@link 
Converter#DEFAULT} if absent.
      *
+     * @param <T> The Class parameter type. 
      * @param clazz The Class to get the Converter for.
      * @return the registered converter if any, {@link Converter#DEFAULT} 
otherwise.
      * @since 1.7.0
      */
-    public static Converter<?, ?> getConverter(final Class<?> clazz) {
-        return converterMap.getOrDefault(clazz, Converter.DEFAULT);
+    @SuppressWarnings("unchecked") // returned value will have type T because 
it is fixed by clazz
+    public static <T> Converter<T, ?> getConverter(final Class<T> clazz) {
+        return (Converter<T, ?>) converterMap.getOrDefault(clazz, 
Converter.DEFAULT);
     }
 
     /**

Reply via email to