Uploaded image for project: 'Commons DbUtils'
  1. Commons DbUtils
  2. DBUTILS-85

In BeanProcessor#isCompatibleType, can Integer.class.isInstance(value) be replaced by value instanceof Integer (etc)?

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.6, 2.0
    • None

    Description

      In BeanProcessor#isCompatibleType, there is one valid use of the dynamic Class#isInstance() method, followed by several that could surely use the static instanceof keyword:

      if (value == null || type.isInstance(value)) { // <== this needs to be dynamic
          return true;
      
      } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) { // <== this doesn't
          return true;
      
      } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) { // <== nore here
          return true;
      ...
      

      Seems unnecessary (and more verbose) to use the dynamic method where the target class is known at compile time.

      Or am I missing something here?
      If so, let's document why the dynamic method is needed.

      Attachments

        Activity

          People

            Unassigned Unassigned
            sebb Sebb
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: