java的变量是有作用范围的,变量的作用域,在这范围之外无法被调用。想在if外面能用,那么就把它先定义在if之前咯。
String s = null;if((s = "张三") != null){ System.out.println(s); }