Merge pull request #392 from square/eric.primitives
Add error message for accidental primitive usage.
This commit is contained in:
commit
03323ae998
2 changed files with 22 additions and 1 deletions
|
@ -492,7 +492,7 @@ public final class Types {
|
|||
|
||||
static void checkNotPrimitive(Type type) {
|
||||
if ((type instanceof Class<?>) && ((Class<?>) type).isPrimitive()) {
|
||||
throw new IllegalArgumentException();
|
||||
throw new IllegalArgumentException("Unexpected primitive " + type + ". Use the boxed type.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -227,4 +227,25 @@ public final class TypesTest {
|
|||
assertThat(Types.equals(String[].class, Types.arrayOf(String.class))).isTrue();
|
||||
assertThat(Types.equals(Types.arrayOf(String.class), String[].class)).isTrue();
|
||||
}
|
||||
|
||||
@Test public void parameterizedAndWildcardTypesCannotHavePrimitiveArguments() throws Exception {
|
||||
try {
|
||||
Types.newParameterizedType(List.class, int.class);
|
||||
fail();
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertThat(expected).hasMessage("Unexpected primitive int. Use the boxed type.");
|
||||
}
|
||||
try {
|
||||
Types.subtypeOf(byte.class);
|
||||
fail();
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertThat(expected).hasMessage("Unexpected primitive byte. Use the boxed type.");
|
||||
}
|
||||
try {
|
||||
Types.subtypeOf(boolean.class);
|
||||
fail();
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertThat(expected).hasMessage("Unexpected primitive boolean. Use the boxed type.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue