0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Java Silver Switch文

Posted at

Switch文 NullPointerExceptionがスローされる時

・finalで修飾するとcase式で使える

・変数case式では使えない

・引数にnullを渡すとnullpointerexceptionが発生

		final int Num = 0; 
		int num = 0;
		String str=null; 
		
		try {
		switch(str) {//条件はString型
		case "10" : System.out.println("a"); 
		break;
		case "Num":System.out.println("b"); 
		break;
		default:System.out.println("default");
		}
  }
		catch(NullPointerException n){
			System.out.println("nullです"); //nullを入れているため
   }

   
			
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?