Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8310267

Javadoc for Class#isPrimitive() is incorrect regarding Class objects for primitives

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 22
    • None
    • core-libs
    • 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.

            darcy Joe Darcy
            sbrannen Sam Brannen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: