Java三元运算符与if/else在JDK8兼容性方面的区别
Java三元运算符与if/else在JDK8兼容性方面的区别
最近我在阅读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; } }
这个方法是org.springframework.core.MethodParameter
类的成员。代码很容易理解,而注释很难懂。
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...else...
结构有什么区别?