Saturday, June 22, 2019

what are the data types we cannot use in switch statement?

Problem statement:
what are the data types you cannot use as a parameter variable for switch statements in Java 8?

Following are the data types we cannot use as an input parameter variable for switch() statements.
  1. long
  2. float
  3. double
Error: Incompatible type found long, float and double.

public class SwitchStatement {
    public static void main(String[] args) {
        double d = 10.5d;
        switch (d) {
            case 10.5d:
                System.out.println("double");
                break;            
            default:
                System.out.println("default");
                break;
        }
    }
}
Error: Incompatible types. Found: 'double'

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...