View Javadoc
1   /*
2   UnnecessaryNullCheckWithInstanceOf
3   
4   */
5   
6   package com.puppycrawl.tools.checkstyle.checks.coding.unnecessarynullcheckwithinstanceof;
7   
8   public class InputUnnecessaryNullCheckWithInstanceOfSwitch {
9       public void basicSwitch(Object obj, int type) {
10          switch (type) {
11              case 1:
12                  // violation below, 'Unnecessary nullity check'
13                  if (obj != null && obj instanceof String) {
14                      String str = (String) obj;
15                  }
16                  break;
17              case 2:
18                  if (obj instanceof Integer) {
19                      Integer i = (Integer) obj;
20                  }
21                  break;
22              default:
23                  break;
24          }
25      }
26      public void switchWithDefault(Object obj, int type) {
27          switch (type) {
28              case 1:
29                  if (obj instanceof String) {
30                      String str = (String) obj;
31                  }
32                  break;
33              default:
34                  // violation below, 'Unnecessary nullity check'
35                  if (obj != null && obj instanceof Integer) {
36                      Integer i = (Integer) obj;
37                  }
38                  break;
39          }
40      }
41  }