最近我正在阅读Spring Framework的源代码.我无法理解的东西在这里:
public Member getMember() {
// NOTE: no ternary expression to retain JDK <8 compatibility even when using
// the JDK 8 compiler (potentially selecting java.lang.reflect.Executable
// as common type, with that new base class not available on older JDKs)
if (this.method != null) {
return this.method;
}
else {
return this.constructor;
}
}
Run Code Online (Sandbox Code Playgroud)
此方法是类的成员org.springframework.core.MethodParameter.代码很容易理解,而评论很难.
注意:即使使用JDK 8编译器,也没有三元表达式来保持JDK <8的兼容性(可能选择
java.lang.reflect.Executable为通用类型,旧的JDK上没有新的基类)
if...else...在这种情况下使用三元表达和使用构造有什么区别?
我知道如何使用它,但是我在文档中找不到任何解释。我想要一个准确的定义,以便我可以更好地理解它。
编辑:我的意思是in用于映射类型,而不是js运算符。