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.
我从静态类型语言来到 Groovy。而且我不明白隐式转换为布尔有什么好处?我认为这个功能很有争议而不是有用。
这是一种方便。someMap编写条件比.更容易和更短someMap!=null && !someMap.isEmpty()。是的,有些库可以在一次调用中为您完成这两项检查,但随后您会得到MyAwesomeLibrary.makeThisTestForMe(someMap).
someMap
someMap!=null && !someMap.isEmpty()
MyAwesomeLibrary.makeThisTestForMe(someMap)
使用 Groovy 只需更少的代码。
此外,您可以通过将方法重写为asBoolean您喜欢/需要的任何原因来自定义行为。
asBoolean