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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -