Linked Questions

91 votes
15 answers
59k views

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 ...
skaffman's user avatar
  • 405k
1 vote
0 answers
653 views

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 ...
norritt's user avatar
  • 355
-2 votes
1 answer
323 views

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 ...
Andrew Leonard's user avatar
1 vote
0 answers
107 views

The following is allowed:- public interface JustImplementMe { public void ClimbMountain(); } The following is not allowed:- public interface StaticMethodInterface { public static void Climb(); ...
a3.14_Infinity's user avatar
685 votes
29 answers
358k views

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 ...
hhafez's user avatar
  • 39.9k
385 votes
6 answers
53k views

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 ...
Lukas Eder's user avatar
  • 223k
155 votes
14 answers
109k views

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 ...
Henrik Paul's user avatar
75 votes
5 answers
20k views

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,...
user avatar
36 votes
10 answers
26k views

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 ...
Tobias Kienzler's user avatar
12 votes
15 answers
47k views

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 ...
Sarang's user avatar
  • 349
14 votes
8 answers
24k views

Every Java program requires the presence of at least one class. Is the above statement always true ?
Tony's user avatar
  • 1,165
29 votes
7 answers
17k views

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 ...
jayshao's user avatar
  • 2,167
12 votes
11 answers
2k views

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 { ...
polyglot's user avatar
  • 10.2k
10 votes
2 answers
15k views

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 ...
nguyên's user avatar
  • 5,386
5 votes
4 answers
5k views

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 { ...
Frithjof's user avatar
  • 2,264

15 30 50 per page