Idiom to close a cursor

后端 未结 7 1700
刺人心
刺人心 2021-02-08 03:57

Which of the following two should I be using to make sure that all the cursors are closed?

    Cursor c = getCursor(); 

    if(c!=null && c.getCount()&g         


        
相关标签:
7条回答
  • 2021-02-08 04:43

    I'd say the first one, mainly because the second one will try to call c.close() even if c is null. Also, according to the docs, getCount()doesn't throw any exceptions, so there's no need to include it in the try block.

    0 讨论(0)
提交回复
热议问题