How to use functions/methods in SWITCH CASE statement in Java -


i have 3 types of array: controltype controlname controlvalue

when control type "clickbutton", have pass corresponding controlname , controlvalue.

code:

public class stringswitchdemo extends stringswitchdemohelper {     public static int getmonthnumber(string controltype) {         int controlvalue = 0;         int controlname  = 0;          if (controltype == null) {             return controlvalue;         }          switch (controltype.tostring()) {             case clickbutton:                 return controltype(controlvalue, controlname);                 break;         }          return controlvalue;     }      private static int controltype(string controlvalue, string controlname) {         // todo auto-generated method stub          return 0;     } } 

you can use constants (final variables) , literals in switch statements.

public static final string my_const = "foo";  public static int getmonthnumber(string controltype) {     int controlvalue = 0;     int controlname  = 0;      if (controltype == null) {         return controlvalue;     }      switch (controltype) {         case my_const: // work             break;         case "clickbutton":             return controltype(controlvalue, controlname);     }      return controlvalue; }  private static int controltype(int controlvalue, int controlname) {     // todo auto-generated method stub      return 0; } 

also, please read naming conventions java.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -