search

Home  >  Q&A  >  body text

Java中的内部类/内部接口如何引用外部类的类型参数T?

例如:

public class A<T> {

    public interface I<T> {
        //...
    }

    //...

}

想在内部接口I中引用同一个类型参数T,如果做到?

黄舟黄舟2838 days ago910

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:15:40

    Look at this
    http://stackoverflow.com/questions/10963601/java-generics-non-static-type-variable-t-cannot-be-referenced-from-a-static-con

    What you want may not be achievable. The key is to see what your purpose is and then think of individual ways to solve the problem.

    reply
    0
  • 迷茫

    迷茫2017-04-17 13:15:40

    The T in this internal interface has nothing to do with your outer T. You just need to specify the same type when using it

    reply
    0
  • Cancelreply