I'm trying to make a game communication protocol with a superinterface with 2 subinterfaces, but I want to make sure that no one will accidentally implement the superinterface. I can make a class abstract to prevent initialization, but allow extension. Is there a similar thing I can do to an interface to prevent implementation, but allow extension?
Asked
Active
Viewed 199 times
0
-
1How would something like this be useful? – Henry Jan 16 '19 at 14:32
-
Possible duplication: https://stackoverflow.com/questions/3694070/can-you-write-an-interface-that-can-not-be-implemented – Raduan Santos Jan 16 '19 at 14:33
-
Package-private superinterface and public child interfaces? – Michael Jan 16 '19 at 14:35
-
2@Aaron Isn't this question about unimplementable interfaces as well? – khelwood Jan 16 '19 at 14:39
-
@khelwood err, I guess I got confused. – Aaron Jan 16 '19 at 14:40
-
@Michael II guess that would be the closest you can get in Java, but of course anyone who's determined enough could still just place the implementations in the same package. It would prevent accidential misuse, though. – Hulk Jan 16 '19 at 14:47
1 Answers
3
No, there is no such construct.
It is not possible to define an interface that can be extended but not implemented in Java.

Hulk
- 6,399
- 1
- 30
- 52