Current implementation of findViewById() :
public class View {
public final View findViewById(int id) {
if (id < 0) {
return null;
}
return findViewTraversal(id);
}
}
Ideal implementation with generic return type, leveraging the super powers of the java compiler:
public class View {
public final <T extends View> T findViewById(int id) {
if (id < 0) {
return null;
}
return (T) findViewTraversal(id);
}
}
The advantage would be that instead of:
TextView textView = (TextView) myView.findViewById(R.id.text);
One could write:
TextView textView = myView.findViewById(R.id.text);
This means noise reduction: getting rid of the unecessary cast.
Would such a change break Android backward compatibility? Discuss.
That's brilliant.
Moreover I can't find any backward compatibility issue.