Call to method of static java.text.DateFormat not advisable?

前端 未结 8 1822
失恋的感觉
失恋的感觉 2020-12-09 14:55

I am receiving a Find Bugs error - call to method of static java.text.DateFormat and I don\'t know the reason why it\'s not good / advisable to be

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 15:16

    I'm not sure if FindBugs is complaining about this, but one problem I see with your code is that you're defining TODAY as a class level (static), constant (final) variable. This communicates the intent that you want TODAY to never change (I don't believe this is the case, since java.util.Dates are mutable, but that's another story).

    Think about what happens if you application runs for multiple days? TODAY (unless you update it) will be referencing the day the application was started, not the current date. Are you sure this is what you meant?

    This may not be a bug in your code at all, but the intent is not clear, and I believe that may be what FindBugs is complaining about.

提交回复
热议问题