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

[lworld] Compiler should emit a warning if code compares the result of getClass() against the class literal for an interface

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • repo-valhalla
    • repo-valhalla
    • tools
    • generic
    • generic

      From http://cr.openjdk.java.net/~briangoetz/valhalla/sov/02-object-model.html:

      There is one possible incompatibility mode from such a migration – if the client compares the getClass() result with M.class. Pre-migration, an instance of Optional has class Optional.class; once Optional is migrated to an interface, instances of Optional will report some implementation class when queried with getClass.

      This incompatibility surrounding use of M.class is the major compatibility cost of the migration approach outlined here. This can be mitigated somewhat by issuing compiling warnings when comparing the getClass() result with == against the class literal for an interface, since this will be known to fail at runtime.

            sadayapalam Srikanth Adayapalam (Inactive)
            sadayapalam Srikanth Adayapalam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: