is it possible to create a function to shorten casts, like (pseudocode):
MyFragment fragment = (MyFragment) getFragmentManager().findFragmentByTag("mytag");
//shorten:
findByTag(MyFragment.class, "mytag");
private Fragment findByTag(Class<?> cast, String tag) {
return (cast) getFragmentManager().findFragmentByTag(tag);
}
Fix your code as following:
Now you can call it without casting: