Recently I'm reading the source code of Spring Framework. Something I can't understand goes here:
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;
}
}
This method is a member of class org.springframework.core.MethodParameter
. The code is easy to understand while the comments are hard.
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)
What's the difference between using ternary expression and using if...else...
construct in this context?