java - Restrict the classes that may implement an interface -
generally speaking, possible restrict classes may implement interface?
more specifically, can generic interface foo<t>
restrict implementations descendants of t
:
interface foo<t> {} class baz extends bar implements foo<bar> {} // desirable class baz extends bar implements foo<qux> {} // undesirable
the context foo<bar>
objects should castable bar
objects in type-safe way.
having exhausted other sources of information, have strong hunch isn't possible—but delighted if prove otherwise!
if ability cast not strictly necessary, adding additional method interface might suffice:
public t gett()
if implementations extend t
, can return this
implementation of method.
Comments
Post a Comment