Tla*_*-ES 8 android suppress-warnings
当我在Android Studio中为我的项目创建抽屉栏时,在下一个选择项的代码中:
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
Run Code Online (Sandbox Code Playgroud)
但是这个注释的用途是什么?
警告本身就解释了含义。
返回类型onNavigationItemSelected是boolean.,我们需要返回任何boolean值。
如果有条件if没有onNavigationItemSelected返回则@SuppressWarnings("StatementWithEmptyBody")需要添加。
例子:
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
if (id == R.id.xyz) {
// you should return boolean value here.
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
false在示例中,我们默认返回。并且我们没有返回任何值
if (id == R.id.xyz)健康)状况。
你可以清楚地看一下警告。
| 归档时间: |
|
| 查看次数: |
1225 次 |
| 最近记录: |