Linked Questions
16 questions linked to/from Why can't I declare static methods in an interface?
3 votes
1 answer
632 views
why interface doesn't support static method? [duplicate]
Possible Duplicate: Why can’t I declare static methods in an interface? Inside the interface body we aren't able to declare or define any static method. What is the reason? Can any one ...
576 votes
24 answers
457k views
Why can't I define a static method in a Java interface?
NOTE: This question predates Java 8. As of Java 8, static methods are allowed in interfaces. However, they cannot be declared abstract (required to be overridden) in the manner requested by this ...
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,...
8 votes
4 answers
6k views
What is Interface-based framework?
I was going through Effective Java and reading static factory methods for creating objects. Its chapter 2, Item 1. There in the advantage no. 3, the writer has mentioned like Hiding implementation ...
12 votes
4 answers
6k views
Is it possible to specify a generic constraint for a type parameter to be convertible FROM another type?
Suppose I write a library with the following: public class Bar { /* ... */ } public class SomeWeirdClass<T> where T : ??? { public T BarMaker(Bar b) { // ... play with b ...
3 votes
4 answers
2k views
Why can't implementing classes define an overriding method as static?
I'm confused why the following is not allowed: public interface MyInterface { MyInterface getInstance(String name); } public class MyImplementation implements MyInterface { public ...
2 votes
6 answers
1k views
Why java interfaces can't contain static methods implementations?
I'm just curious, wouldn't it be more convinient to allow interfaces to contain implementations of static methods? Such methods could contain short commonly used(by this interface implementors) logic.
4 votes
1 answer
4k views
Java annotation for enforcing static variables or static methods?
I'm interested in doing something like this: public interface Foo { public static "abstract" Bar SOME_BAR; // subclasses define one of these } and public interface Foo { public static "...
0 votes
2 answers
2k views
Java interface asks for method body
I have written this java code public interface Sorter { public static <T extends Comparable<T>> void sort(T[] array); } and the compiler throws this error at me: Sorter.java:7: ...
1 vote
3 answers
1k views
Implements method of interface, method call and type cast
Consider the followoing code interface MyInterface{ void method(String s);// if we write static modifier we have compile error } class MyClass implements MyInterface{ public static void main(...
1 vote
4 answers
901 views
What is the alternative to static in java interface
I have a design question. I have an interface that read XML. Each implementer class read different XML and I want a way to identify which implementer should I dynamically create for the xml type I ...
1 vote
4 answers
183 views
How to reference a class that follows a protocol in return type of function?
I have a protocol called Social Service, declared as follows: protocol SocialService: class { class func testFunc() } A class that follows the protocol may look like this: class Twitter: ...
4 votes
3 answers
227 views
Static method in interface
I defined an interface IPersistent that has two methods load and save. Using these methods I can load or save the implementing class using whatever method they want. public interface IPersistent { ...
0 votes
2 answers
153 views
Java: Am I missing a restricting pattern? I need to restrict implementation with only selected methods
Say I have some class that is too fat of methods for one concrete case, but fits to about a half of them, so it is no way but to extend it. Simultaneously, I want to hide the fact that I've extended ...
1 vote
3 answers
134 views
Static methods and interfaces in Java
I Have a UserEntity class which implements the IUserEntity interface. In the UserEntity class I have a static map: private static Map<IUserEntity.IIdentifiable, IUserEntity> ...