I wonder what's the difference between static interface with usual interface without such keyword in java?
And When and where we should use the static keyword before interface.And why we should use it ? You can take this interface as an example
Thank you so much!
public static interface Map.Entry<K,V>
Static variables are shared among all instances of a class. Non static variables are specific to that instance of a class. Static variable is like a global variable and is available to all methods. Non static variable is like a local variable and they can be accessed through only instance of a class.
Java interface static method is similar to default method except that we can't override them in the implementation classes. This feature helps us in avoiding undesired results incase of poor implementation in implementation classes. Let's look into this with a simple example.
Similar to Default Method in Interface, the static method in an interface can be defined in the interface, but cannot be overridden in Implementation Classes. To use a static method, Interface name should be instantiated with it, as it is a part of the Interface only.
Defining a static method within an interface is identical to defining one in a class. Moreover, a static method can be invoked within other static and default methods.
There's no difference: static
is implied - all interfaces are effectively static.
The use or not or the static
keyword is a matter of style. Personally, I prefer to use static
as it's in keeping with the semantics of an inner static class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With