0

I want each class that implements an interface to have a static factory method, as defined by the interface. I.e:

public interface Handle { public static Handle GetHandle() { return null; } public void DoThings(); } public class HandleA implements Handle { private HandleA(); public static HandleA GetHandle() { return new HandleA(); } public void DoThings() { return; } } // This is allowed even though HandleB doesn't provide a GetHandle() public class HandleB implements Handle { private HandleB(); public void DoThings() { return; } } 

Reading past questions, it seems like the static method GetHandle() isn't enforced in concrete classes of Handle because that's not what the intended design behavior of static interface method is. Is there another way to do what I want? (i.e enforce all implementations of Handle to provide a "factory" GetHandle() method).

0

1 Answer 1

0

You cant enforce a class to have a static method in Java.

Sign up to request clarification or add additional context in comments.

1 Comment

and you can't abstract them either: stackoverflow.com/questions/370962/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.