Static methods added in interfaces in java 1.8 -


as know in java 1.8 static methods allowed in interfaces , have seen answers static methods defined in interface jdk 1 8 why did need so
not satisfied.
furthermore think may cause problems :

 public interface myinterface{       public static void mymethod();     }    class myclass{     myinterface.mymethod();  // since mymethod static huge error waiting here ?   } 

but still think there way out of since added by professionals , can please explain how oracle solves issue , need add ?
thank in adavance.


have not used java 1.8 never knew static methods in java needs defined not declared , thought of interfaces pure abstract class think that's why idea of defining method seemed strange me . thank ! .

talking "what need add" static methods:

quoting http://www.informit.com/articles/article.aspx?p=2191423

before java 8 made possible declare static methods in interfaces, common practice place these methods in companion utility classes. example, java.util.collections class companion java.util.collection interface, , declares static methods more appropriate in relevant java collections framework interfaces. no longer need provide own companion utility classes. instead, can place static methods in appropriate interfaces, habit cultivate.

also static methods in interfaces providing utility methods null check, collection sorting etc. and importantly provides security denying implementation classes overriding it.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -