Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道为什么以下编译:
Locale aLocale = new Locale.Builder().setLanguage("trollolo").setRegion("CA").build(); System.out.println(aLocale.getLanguage());
因为“trollolo”不是一种语言。为什么它不返回运行时异常,而是在调用时甚至返回“trollolo” getLanguage()?
getLanguage()
这是允许的行为。来自javadoc
Builder 仅检查单个字段是否满足语法要求(格式正确),但不验证值本身。
语法 (IETF BCP 47) 在用于识别语言的标签中定义