Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing Java interface in Kotlin

Tags:

android

kotlin

I have a Java interface:

public interface NonHindiQuery {
    void onNonHindiQueryReceived(String Query);
}

I want to implement it on Kotlin class:

class MainActivity : AppCompatActivity() {...}

Q: How can I do it?

like image 237
Hamza Avatar asked Jun 28 '17 10:06

Hamza


1 Answers

It's simple:

class MainActivity : AppCompatActivity(), NonHindiQuery {
    override fun onNonHindiQueryReceived(q: String) {
        // <...>
    }
}

To get rid of kotlin.NotImplementedError remove TODO("not implemented") from the method body:

@kotlin.internal.InlineOnly
public inline fun TODO(reason: String): Nothing = 
    throw NotImplementedError("An operation is not implemented: $reason")
like image 77
Alexander Romanov Avatar answered Sep 22 '22 11:09

Alexander Romanov