我有以下场景..我多次遇到类似的场景。以下两个选项中哪个更可取?
选项1:
String result = ( getDetails(...) == null ) ? "" : getDetails(...);
Run Code Online (Sandbox Code Playgroud)
选项 2:
String returnValue = getDetails(...);
String result = ( returnValue == null ) ? "" : returnValue;
Run Code Online (Sandbox Code Playgroud)
哪个更可取和/或更好的做法。?