Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-6380

Add Default hint for Swithc Pattern matching

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • java - Hints
    • None

    Description

      In switch pattern matching, the error "the switch statement does not cover all possible input values" is thrown in the given case :

      static void error2(Object o1) {
              switch (o1) { 
                  case null ->
                      System.out.println("null case");   
                  case Integer i && i > 0 ->
                      System.out.println("2nd case");  // Positive integer cases  
                  case Integer i ->
                      System.out.println("3rd case" + i);           // All the remaining integers 
              }
          } 

      The IDE can give a hint for the switch expression for adding a default to the switch statement/expression which will fix the error as given below :

          static void error2(Object o1) {
              switch (o1) { 
                  case null ->
                      System.out.println("null case");   
                  case Integer i && i > 0 ->
                      System.out.println("2nd case");  // Positive integer cases  
                  case Integer i ->
                      System.out.println("3rd case" + i);           // All the remaining integers 
                  default -> throw new IllegalStateException("Unexpected value: " + o1);
              }
          } 

      Attachments

        Activity

          People

            mishra.sandeep Sandeep Mishra
            mishra.sandeep Sandeep Mishra
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: