我想将结果指定为“read_only”、“write_only”或“read_write”。为此我想检查resourceKey。
result = resourceKey.get("read") == null ?
Constants.WRITE_ONLY :
resourceKey.get("write") == null ?
Constants.READ_ONLY :
Constants.READ_WRITE;
我想简化这个三元条件。
最佳答案
考虑将此功能分解为实用函数。
void Thing() {
// stuff
var result = GetPermissions(resourceKey);
// other stuff
}
static int GetPermissions(resourceKey) {
if( resourceKey.get("read") == null )
return Constants.WRITE_ONLY;
if( resourceKey.get("write") == null )
return Constants.READ_ONLY;
return Constants.READ_WRITE;
}
关于java - 简化复杂的三元条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56571374/