Implementing abstract functions with the same name twice

Hello! I’m a beginner with Kotlin, but taking small steps. However, I’ve had to examine some code, and the existing code contains this:

public interface Bob {
public abstract fun onError(err: kotlin.Unit
public abstract fun onError(err: kotlin.Unit

In my code, I have typed:
AFragment.newInstance(“identifier”, myListener =
object : Bob{
override fun onError(err: ErrorResponse) {
override fun onError(err: HardwareError) {

However, I get a compiler error "Object is not abstract and does not implement abstract member public abstract fun onError(err: HardwareError): Unit defined in

If I comment out one or the other “override fun onError…” snippets, then the compiler error just moves from on of the onError definitions to the other. So, I believe I’m not implementing those abstract functions properly, but googling isn’t helping : ( If I could, I’d work around the problem by changing the original abstract declarations so that the functions had different names, but I cannot do that unfortunately.

I think I should be using the keyword super? But I’m not sure if I’m heading in the wrong direction. Any direct help, or even tips, would be great. Apologies if this was a very trivial issue.

Please ignore, I’ve solved it. The solution was to use autocomplete properly in Android Studio, and it changed the second onError parameter to
Now it compiles fine.

You can look into function overloading if you want to better understand what’s going on, and how functions with the same name (but different parameters) work

1 Like