-
Bug
-
Resolution: Fixed
-
P4
-
None
-
None
The Javadoc for java.lang.Class.isPrimitive() currently states:
> These objects may only be accessed via the following public static final variables, and are the only Class objects for which this method returns true.
However, it is also possible to access each of the Class objects for primitives via boolean.class, byte.class, char.class, short.class, int.class, long.class, float.class, double.class, and void.class.
For example, the following unit test (using JUnit Jupiter and AssertJ) passes.
@Test
void isPrimitive() {
assertThat(Integer.TYPE).isEqualTo(int.class);
assertThat(Integer.TYPE).isSameAs(int.class);
assertThat(Integer.TYPE.isPrimitive()).isTrue();
assertThat(int.class.isPrimitive()).isTrue();
}
Please update the Javadoc for java.lang.Class.isPrimitive() to reflect that.
> These objects may only be accessed via the following public static final variables, and are the only Class objects for which this method returns true.
However, it is also possible to access each of the Class objects for primitives via boolean.class, byte.class, char.class, short.class, int.class, long.class, float.class, double.class, and void.class.
For example, the following unit test (using JUnit Jupiter and AssertJ) passes.
@Test
void isPrimitive() {
assertThat(Integer.TYPE).isEqualTo(int.class);
assertThat(Integer.TYPE).isSameAs(int.class);
assertThat(Integer.TYPE.isPrimitive()).isTrue();
assertThat(int.class.isPrimitive()).isTrue();
}
Please update the Javadoc for java.lang.Class.isPrimitive() to reflect that.
- relates to
-
JDK-6361826 (reflect) provide method for mapping strings to class object for primitive types
-
- Resolved
-
- links to
-
Commit openjdk/jdk/0314292c
-
Review(master) openjdk/jdk/14574