Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between static interface with usual interface without such keyword in java?

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>

like image 890
andyqee Avatar asked Nov 27 '12 02:11

andyqee


People also ask

What is the difference between static and non static keyword in Java?

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.

What is difference between static and default methods in interface Java?

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.

What is static interface in Java?

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.

Can we have static and default methods in interface?

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.


1 Answers

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.

like image 193
Bohemian Avatar answered Sep 28 '22 19:09

Bohemian