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

Improvement in the usage of instanceof statement

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :
      generic
      JDK15+

      A DESCRIPTION OF THE PROBLEM :
      see the code:

      Type1 a = ...;
      Type2 b = a instanceof Type2 c ? c : null;
      Type3 c = ...;

      [Phenomenon]
      The Variable c in line 2 is used in and only in the second line, and it will not have any impact on subsequent code。
      [Recommendation]
      so, we can remove the c in line 2 if possible, and at the same time, it can avoid misunderstandings about the naming of subsequent code.
      Next are several possible grammars:
      var b = a instanceof Type2 | null;
      or
      var b = a instanceof -> Type2;
      or
      var b = a -> Type2;
      or
      Type2 b = a | null;



      Attachments

        Activity

          People

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: