|
6 | 6 |
|
7 | 7 | import java.util.Collection;
|
8 | 8 | import java.util.Collections;
|
| 9 | +import java.util.HashMap; |
9 | 10 | import java.util.Map;
|
10 | 11 | import java.util.Optional;
|
11 | 12 | import java.util.function.Supplier;
|
@@ -48,6 +49,17 @@ public record CommandArguments(
|
48 | 49 | String fullInput
|
49 | 50 | ) {
|
50 | 51 |
|
| 52 | + private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER = new HashMap<>() {{ |
| 53 | + put(boolean.class, Boolean.class); |
| 54 | + put(char.class, Character.class); |
| 55 | + put(byte.class, Byte.class); |
| 56 | + put(short.class, Short.class); |
| 57 | + put(int.class, Integer.class); |
| 58 | + put(long.class, Long.class); |
| 59 | + put(float.class, Float.class); |
| 60 | + put(double.class, Double.class); |
| 61 | + }}; |
| 62 | + |
51 | 63 | // Access the inner structure directly
|
52 | 64 |
|
53 | 65 | /**
|
@@ -487,10 +499,10 @@ private <T> T castArgument(Object argument, Class<T> argumentType) {
|
487 | 499 | if (argument == null) {
|
488 | 500 | return null;
|
489 | 501 | }
|
490 |
| - if (!argument.getClass().equals(argumentType)) { |
| 502 | + if (!argument.getClass().equals(PRIMITIVE_TO_WRAPPER.getOrDefault(argumentType, argumentType))) { |
491 | 503 | return null;
|
492 | 504 | }
|
493 |
| - if (!argumentType.isAssignableFrom(argument.getClass())) { |
| 505 | + if (!PRIMITIVE_TO_WRAPPER.getOrDefault(argumentType, argumentType).isAssignableFrom(argument.getClass())) { |
494 | 506 | return null;
|
495 | 507 | }
|
496 | 508 | return (T) argument;
|
|
0 commit comments