Should I use static import?

前端 未结 7 605
天命终不由人
天命终不由人 2020-12-16 12:45

How important it is to convert all my import to static import? Why are people still reluctant to use static import?

7条回答
  •  暖寄归人
    2020-12-16 13:12

    This is a special case but also the perfect use case (and I use it in all my tests):

    import static junit.framework.Assert.*;
    

    Here, I find that this makes my tests more readable and it's obvious from where assertXXX come from. But this is an exception. In other situations, I find that static import make things more obscure, harder to read and I don't really use them.

提交回复
热议问题