Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlexey Mironov
587 PointsAbout OnClickListener
How did we create an instance of interface? Because in Java we can't create instance of interface.
2 Answers
Kourosh Raeen
23,733 PointsHi Alexey - We're not creating an instance of an interface. We're creating an instance of an anonymous class that implements the interface.
Take a look at this link to learn more about anonymous classes:
https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html
Tam İbrahim
61 PointsIf you put ({}) then it will work or try @overcaul (id, Rb)
vicente lee
6,271 Pointsvicente lee
6,271 PointsSince we cannot create an instance of A, we need to do something like this:
SomeInterface foo = new SomeClass();