This version of View.findViewById()
returns the most specific concrete subtype of View
:
protected <T extends View> T findViewById(@IdRes int id) {
return (T) getRootView().findViewById(id);
}
How does it work? Specifically, how can the type be inferred at compile-time when the id
is looked up at runtime? Does it have to do with the annotation?
This differs from questions with similar titles, which are about the use of findViewById()
:
I would like to know why it works.