Explanation
1. When an object of an outer class creates an object of an inner class, the object of the inner class must secretly capture a reference to the object of the outer class.
2. When accessing members of an external category, use this reference to select members of the external category. Of course, these editors already help us with that.
In addition, please note that internal classes are only a compilation phenomenon and have nothing to do with the virtual machine. The compiler compiles the inner class into a regular file with outer class name $ inner class name, and the virtual machine knows nothing about it.
Example
class MainActivity extends AppCompatActivity{ .... private List<Fragment> fragments = new ArrayList(); private class BottomPagerAdapter extends FragmentPagerAdapter{ .... @Override public Fragment getItem(int position) { return fragments.get(position); } ... } ... }
The above is the detailed content of What is the access method of Java internal classes?. For more information, please follow other related articles on the PHP Chinese website!