Linked Questions
43 questions linked to/from Why can't I define a static method in a Java interface?
91 votes
15 answers
59k views
Why no static methods in Interfaces, but static fields and inner classes OK? [pre-Java8] [duplicate]
There have been a few questions asked here about why you can't define static methods within interfaces, but none of them address a basic inconsistency: why can you define static fields and static ...
1 vote
0 answers
653 views
How can generic interfaces define static generic methods (without body) in Java 8? [duplicate]
Since Java 8 supports static interface methods (according to the answer to this related question) I've been trying to write code that looks like this: Example 1 public interface ITest<T extends ...
-2 votes
1 answer
323 views
Java, declaring static methods in interface [duplicate]
This subject already has questions and answers, none with conclusive results. If this is not possible, then can someone determine the best workaround? Some of the answers say that this is possible ...
1 vote
0 answers
107 views
Can interfaces have static methods or java class stati'fy interface method? [duplicate]
The following is allowed:- public interface JustImplementMe { public void ClimbMountain(); } The following is not allowed:- public interface StaticMethodInterface { public static void Climb(); ...
685 votes
29 answers
358k views
Why can't static methods be abstract in Java?
The question is in Java why can't I define an abstract static method? for example abstract class foo { abstract void bar( ); // <-- this is ok abstract static void bar2(); //<-- this ...
385 votes
6 answers
53k views
Why is "final" not allowed in Java 8 interface methods?
One of the most useful features of Java 8 are the new default methods on interfaces. There are essentially two reasons (there may be others) why they have been introduced: Providing actual default ...
155 votes
14 answers
109k views
Why can't I declare static methods in an interface?
The topic says the most of it - what is the reason for the fact that static methods can't be declared in an interface? public interface ITest { public static String test(); } The code above gives ...
75 votes
5 answers
20k views
Why are class static methods inherited but not interface static methods?
I understand that in Java static methods are inherited just like instance methods, with the difference that when they are redeclared, the parent implementations are hidden rather than overridden. Fine,...
36 votes
10 answers
26k views
Is there a way to make sure classes implementing an Interface implement static methods?
First of all, I read erickson's useful reply to "Why can’t I define a static method in a Java interface?". This question is not about the "why" but about the "how then?". Edit: my original example ...
12 votes
15 answers
47k views
Why Interface methods cannot be "static" & "final"?
In Java Interface, we can have only final variables possible. We can also create static variables in Interface. But, at the same time we are not able to create static/final methods as Interface are ...
14 votes
8 answers
24k views
Does every program in Java require a class?
Every Java program requires the presence of at least one class. Is the above statement always true ?
29 votes
7 answers
17k views
Alternatives to static methods on interfaces for enforcing consistency
In Java, I'd like to be able to define marker interfaces, that forced implementations to provide static methods. For example, for simple text-serialization/deserialization I'd like to be able to ...
12 votes
11 answers
2k views
"Abstract static" method - how?
There are already several SO questions on why there is not abstract static method/field as such, but I'm wondering about how one would go about implementing the following psuedo-code: class Animal { ...
10 votes
2 answers
15k views
how can I declare java interface field that implement class should refine that field
How can I declare java interface field that implement class should refine that field ? for example public interface IWorkflow{ public static final String EXAMPLE;// interface field public ...
5 votes
4 answers
5k views
Eclipse does not allow access to static interface method in external jar from another workspace
There are two eclipse workspaces, Workspace A and Workspace B. In Workspace A, there is a project with an interface defining a public static method: package workspacea; public interface Foo { ...