Idiom to close a cursor

后端 未结 7 1699
刺人心
刺人心 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:42

    Depends on what you're catching, but I'd say the second one, just in case c.getCount() throws an exception.

    Also, some indentation wouldn't go amiss :)

提交回复
热议问题