Changes in access of variables for generic classes in Java 7

后端 未结 3 947
借酒劲吻你
借酒劲吻你 2021-01-01 18:03

Here is a simple example of some code that compiles using Java 6, but does not compile in Java 7.

public class Test {

  private final         


        
3条回答
  •  悲哀的现实
    2021-01-01 19:06

    A workaround for this is to cast the generic instance to the concrete supertype that declares the private field, e.g.

    public int get(TestContainer container){
      T t = container.get();
      return ((Test) t)._myVar;
    }
    

提交回复
热议问题