0
public class Test {

public void test(){
    Demo demo = new Demo();
    TextView textView = demo.getView(1);
}


class Demo {

    private View ContentView = null;

    public <T extends View> T getView(int id){
        return ContentView.findViewById(id);
    }
}

}

The above is no problem.The following compilation fails, requiring a strong wall conversion type

public class Test {

public void test(){
    Demo demo = new Demo();
    TextView textView = demo.getView(1);
}


class Demo<B> {

    private View ContentView = null;

    public <T extends View> T getView(int id){
        return ContentView.findViewById(id);
    }
}

}

I just added a generic type of the class and had to force it when calling getView ().why?thanks

super_mark
  • 11
  • 2

0 Answers0