Android 为什么“noinspection SimplifiableIfStatement”会自动添加到通过向导创建的活动中
通过向导创建的“我的活动”散列了以下代码:Android 为什么“noinspection SimplifiableIfStatement”会自动添加到通过向导创建的活动中,android,Android,通过向导创建的“我的活动”散列了以下代码: @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent acti
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
这段代码是什么
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
如果没有
//noinspection SimplifiableIfStatement
,编辑器会警告您,因为这可能会简化为:
return id == R.id.action_settings;
但这可能不是您想要的,您需要在以后的
中添加一些内容(例如启动设置活动)。谢谢,但是为什么默认情况下会在此处添加此代码?我不是指注释禁用检查,我是指returnid==R.id.action\u设置代码>您了解如何工作吗?默认情况下,向导会创建一个设置菜单,因此此代码的意思是:“如果单击设置菜单,请执行某些操作”(此处它仅返回true
)。模板确实应该在if块中添加注释以“在此处添加设置处理”。不确定这是否解决了过度急切的编辑器警告。