Quick Java question about private static final keywords for fields

前端 未结 7 1092
梦如初夏
梦如初夏 2020-12-13 18:48

I\'m declaring a field:

private static final String filename = \"filename.txt\";

First, does the order of private static final

7条回答
  •  伪装坚强ぢ
    2020-12-13 18:51

    1. The order doesn't matter, but you can always play around with it - there's only 6 possibilities to test.

    2. I'm not aware of any convention, though I put the visibility modifier first (public/private/protected) so you can eyeball it and it lines up.

    3. If it's fixed then you can do that, but I always think something is a constant only to discover later (during testing, for example) that I want to pass it in. An argument on the command line or a properties file works for that case, and is a minimum of effort to set up.

提交回复
热议问题