2012-02-02 79 views
1

我在網上找到了以下代碼。我對第一行感到困惑。這條線的目的是什麼?「@SuppressWarnings(」unchecked「)」的用途是什麼?

@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(); 
} 

回答

5

該方法的代碼中存在未檢查的泛型轉換/轉換。

因此,通過指示@SuppressWarnings註釋,您不會從IDE或編譯中收到警告,因爲您告訴編譯器您知道並且不會收到警告。