WARNING: File.mkdir() is ignored

后端 未结 4 1768
忘了有多久
忘了有多久 2021-01-04 10:49

I\'ve created a basic Audio Recording App using Media Recorder API\'s. I\'m trying to create a folder in the SD card and to save my recorded files to that folder. I\'m getti

4条回答
  •  清酒与你
    2021-01-04 11:32

    I created a utility function:

    @SuppressWarnings("unused")
    private static void IGNORE_RESULT(boolean b) {}
    

    And then to use:

    IGNORE_RESULT(path.mkdir());
    

    I like this solution because it is self documenting. You are explicitly stating that you know there is a result and you are intentionally ignoring it. It should also optimize out to a NOP during compilation so there is no unnecessary test at runtime just to suppress a useless warning.

提交回复
热议问题