//摘自ocjp public void testIfA() { if (testIfB("True")) { System.out.println("True"); } else { System.out.println("Not true"); } } public Boolean testIfB(String str) { return Boolean.valueOf(str); } What is the result when method testIfA is invoked? A. True B. Not true C. An exception is thrown at runtime. D. Compilation fails because of an error at line 12. E. Compilation fails because of an error at line 19. Answer: A
分析:
查看API:
//摘自Jdk1.6.21 API--Boolean类。 public static Boolean valueOf(String s) { return toBoolean(s) ? TRUE : FALSE; } private static boolean toBoolean(String name) { return ((name != null) && name.equalsIgnoreCase("true")); }
不难看出,此处不区分大小写。
时间: 2024-12-30 03:55:46