我在网上找到了以下代码。我对第一行感到困惑。这条线的目的是什么?
@SuppressWarnings("unchecked")
private void showAlert(String title,String msg,final Class cls)
{
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(title);
alertDialog.setMessage(msg);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent samepage = new Intent(LoginActivity.this,
cls);
startActivity(samepage);
}
});
alertDialog.setIcon(R.drawable.icon);
alertDialog.show();
}
最佳答案
方法内部的代码中有未经检查的泛型转换/强制转换。
因此,通过指示@SuppressWarnings
批注,您不会从IDE或编译中得到警告,因为您告诉编译器您已经知道并且没有收到警告。