How to create an instance of anonymous interface in Kotlin?

Posted by Andre Scott | Updated on

If you want to create an instance of anonymous interface in Kotlin? Assuming the interface has only a single method you can make use of SAM.

If you have a method that accepts a handler then you can even omit type arguments:

If the interface has more than one method the syntax is a bit more verbose:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers