When NOT to use the static keyword in Java?

后端 未结 9 863
轮回少年
轮回少年 2020-11-27 13:29

When is it considered poor practice to use the static keyword in Java on method signatures? If a method performs a function based upon some arguments, and does not require a

9条回答
  •  庸人自扰
    2020-11-27 14:17

    An additional annoyance about static methods: there is no easy way to pass a reference to such a function around without creating a wrapper class around it. E.g. - something like:

    FunctorInterface f = new FunctorInterface() { public int calc( int x) { return MyClass.calc( x); } };
    

    I hate this kind of java make-work. Maybe a later version of java will get delegates or a similar function pointer / procedural type mechanism?

    A minor gripe, but one more thing to not like about gratuitous static functions, er, methods.

提交回复
热议问题