For java,how to make sure inner interface and outer interface have same generic type?

Firstly, there is no way to do this, since the outer interface is nothing more than a "namespace" for the inner interface. They really have nothing else to do with each other This begs the question: why would you need to have such a control over things? If, in the class which implements the interface, it is decided that using the same type makes sense, then it will be so for that class.

But another implementation could, and should be allowed to, choose otherwise. This is especially true since classes which implement Outer and those implementing Inner are not restricted to being nested with each other.

Firstly, there is no way to do this, since the outer interface is nothing more than a "namespace" for the inner interface. They really have nothing else to do with each other. This begs the question: why would you need to have such a control over things?

If, in the class which implements the interface, it is decided that using the same type makes sense, then it will be so for that class. But another implementation could, and should be allowed to, choose otherwise. This is especially true since classes which implement Outer and those implementing Inner are not restricted to being nested with each other.

The source of your problem is this ; Inner interface is static , therefore it is not related any instanceof Outer interface. Therefore you can not use, Outer interface generic type for Inner interface.. According to JLS ; 9.5 Member Type Declarations Interfaces may contain member type declarations (§8.5). A member type declaration in an interface is implicitly static and public.

What you should do is, possibly, have Inner extends Outer, if the type must absolutely be enforced, but of course, you'll have to implement methods of both Inner and Outer. I'm not sure you want this. Interface Outer { interface Inner extends Outer { T myMethod(T t); } } There isn't really another way to enforce what you want.

The reason is that an interface is always static. Also, you don't really want/need this behavior: an interface is already flexible enough for you. Just learn where you may have control over this and the world will be yours!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions