I trying to migrate from Eclipse to Android Studio. The code compiles and works in Eclipse but won't compile in Android Studio.
The code in question is converting a list from a type to a list of a subtype. It uses the method mapList which uses generics.
Android Studio is complaining that the argument to mapList to be the same as the resulting type.
Is there a problem with the code or Android Studio?
public class Fruit {
}
public class Banana extends Fruit {
}
private <D, S extends D> List<D> mapList(List<S> sourceList) {
List<D> result = new ArrayList<D>();
for(S sourceElement : source) {
result.add((D) sourceElement);
}
return result;
}
private void bananaToFruit() {
List<Banana> bananaList = new ArrayList<Banana>();
List<Fruit> fruitList = mapList(bananaList);
}