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

Add the method `Class::isSublassOf(Class<?>)` to `java.lang.Class` that does the inverse of `Class::isAssignableFrom`

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      As explained in [https://github.com/openjdk/jdk/pull/7061#issuecomment-1046816442], `Class::isAssignableFrom` tends to be used incorrectly (see: JDK-8034820, JDK-8254717, and JDK-8279800).

      I propose to add the following method to `java.lang.Class`, which should hopefully be clearer about the order of arguments:
      ```java
      public boolean isSublassOf(final Class<?> cls) {
      return cls.isAssignableFrom(this);
      }
      ```

      this method also complements the `Class::asSubclassOf` method.


      Attachments

        Issue Links

          Activity

            People

              smarks Stuart Marks
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: