mlm mlm - 3 months ago 27
Java Question

If FragmentManager.beginTransaction() is not implemented, how can it return a FragmentTransaction object?

The following is some Android java code:

FragmentManager fm = getSupportFragmentManager();
Fragment fragment = new ThisClassExtendsFragment();
fm.beginTransaction().add(R.id.fragment_container, fragment).commit();


I am confused by the call to beginTransaction(). It seems that this is an abstract method, and that it isn't implemented anywhere. How then can it return a FragmentTransaction object?

Answer

It seems that this is an abstract method, and that it isn't implemented anywhere

The implementation is in an internal part of the Android SDK, that you will not be able to see from the JavaDocs.

In this case, it is implemented by FragmentManagerImpl, a nested class inside the FragmentManager class.

Comments