Java: why should static interface methods have a body? -


i need have bunch of classes initialize static method instead of static {...} block initialization tasks run. in java 8 possible define static interface method don't need have body, need know class implements static method.

interface initializable {     static void initialize(){} }  class icons implements initializable {     public static void initialize(){         //...     }      //... } 

what's wrong idea of using static interface methods in case , why not possible define interface static method without body?

general purpose is: initialize collection of classes on application start calling respective methods. initialization tasks are: establishing database connection, rendering icons , graphics, analyzing workstation configuration etc.

what want not possible. interfaces prescribe instance methods need implemented class.

a static method not need instance of containing class run, , thus, if not need private members, can in principle placed anywhere. since java 8, can placed in interface, organisational feature: can put static methods 'belong to' interface in interface, , not need create separate classes them (such collections class).

try following source code:

interface {      static void f() { } }  public b implements { } 

now, trying call b.f() or new b().f() issue compiler error. need call method a.f(). class b not inherit static methods interface.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -