This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How come the instantiation of interface workes in my code  RSS feed

 
Rahul Shivsharan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


can anybody tell me wether we have instantiated interface or what ? i'm not able to understand the above code and how it works
 
Ulrika Tingle
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul Shivsharan wrote:
can anybody tell me wether we have instantiated interface or what ? i'm not able to understand the above code and how it works


You've instantiated an anonymous class.

Anonymous means the class has no name.

The anonymous class is defined on the fly in code, so you can do new on it.
 
Manu Ullas
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul Shivsharan wrote:
can anybody tell me wether we have instantiated interface or what ? i'm not able to understand the above code and how it works


Ulrika Tingle is right. Ex01_24_09 is an anonymous-inner class that implements the Ex01_24_09 interface implicitly. It is anonymous because it doesn't have any name that you can use to refer to it later. And inner because it is defined as part of a statement in a method.

Also ex01 is an object of the anonymous class Ex01_24_09.

This should be able to explain anonymous and inner classes in detail.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!