onDestroy メソッド内で、オブジェクトを閉じる/シャットダウンする前に実際に初期化されたかどうかを判断する正しい方法は何ですか?
たとえば、どちらが優れているか:
protected void onDestroy()
{
if(tts != null)
{
tts.shutdown();
}
if(dbWord != null)
{
dbWord.close();
}
super.onDestroy();
}
またはこれ:
protected void onDestroy()
{
if(tts instanceof null)
{
tts.shutdown();
}
if(dbWord instanceof TextToSpeech)
{
dbWord.close();
}
super.onDestroy();
}