Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why so many inner classes in Android?

Tags:

java

android

I am a new fish in Android development. While reading books and Android source code I found out that there so many inner classes in the Android application. Why does Android need so many inner classes?

I am confused by these inner classes.

like image 904
Chris Avatar asked Jul 12 '10 05:07

Chris


2 Answers

They are often the most efficient way of implementing a design.

An inner class can access the private members of the class which contains it, so using an inner class allows a split of functionality between classes without the need to add accessor methods for private variables.

like image 149
Al Sutton Avatar answered Oct 01 '22 21:10

Al Sutton


Inner classes are not just in Android. I guess you need to understand why they are good in some cases.

Check this article about Inner classes: Inner classes: So what are inner classes good for anyway?.

like image 35
Macarse Avatar answered Oct 01 '22 20:10

Macarse