class Test<G extends String>{
public G test(){return null;}
public List<G> tests(){return new ArrayList<>();}
}
public void doTest(Test t){
//works fine
String str = t.test();
//Compile error: expected String found Object
str = t.tests().iterator().next();
}
I would like the last line to return a String instance instead of Object, as the type G was bound to subclass String. There is any other way than casting ?