Skip to content Skip to sidebar Skip to footer

Implementing Java Interface In Kotlin

I have a Java interface: public interface NonHindiQuery { void onNonHindiQueryReceived(String Query); } I want to implement it on Kotlin class: class MainActivity : AppCompatA

Solution 1:

It's simple:

classMainActivity : AppCompatActivity(), NonHindiQuery {
    overridefunonNonHindiQueryReceived(q: String) {
        // <...>
    }
}

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

@kotlin.internal.InlineOnly
publicinlinefunTODO(reason: String): Nothing = 
    throw NotImplementedError("An operation is not implemented: $reason")

Post a Comment for "Implementing Java Interface In Kotlin"