I think, no.
This question comes from an open discussion.
Rules:
switch(x) may accept primitive and reference variable.
(1) primitives: byte, char, short, and int
(2) reference type: their boxing, i.e Byte, Character, Short, and Integer; as well as String and Enum
The above is all types that switch is able to handle.
The following code will give a compiling error, although reference types mentioned above are Object too. However, Object is not a String, Byte or a Integer.
public class AcceptObject { /** * @param args the command line arguments */ public static void main(String[] args) { Object i = new Integer(9); switch(i){ default:System.out.println("dd"); } } }
No comments:
Post a Comment