Pin*_*juh 5 java if-statement conditional-operator
我if在Java中编写了以下语句:
if(methodName.equals("set" + this.name) ||
isBoolean() ? methodName.equals("is" + this.name) :
methodName.equals("get" + this.name)) {
...
}
Run Code Online (Sandbox Code Playgroud)
在if将状态与条件分开时,这是一个很好的做法吗?这个表达式可以简化吗?
我会改成它
if (methodName.equals("set" + this.name)
|| methodName.equals( (isBoolean() ? "is" : "get") + this.name)) {
...
}
Run Code Online (Sandbox Code Playgroud)