Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class is not abstract and does not implement abstract base class member

I'm confused by this Kotlin error associated with providing an implementation for an abstract class that has been imported from a maven package.

I have a maven library that is written in Kotlin and exposes an abstract class called APIGatewayRequestHandler. In my app that imports the library, I provide an implementation of the abstract class:

class GetWelcomeMessageHandler : APIGatewayRequestHandler<WelcomeMessage>()
    fun handleAPIGatewayRequest(input: com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent, context: com.amazonaws.services.lambda.runtime.Context?): WelcomeMessage {
        return WelcomeMessage()
    }
}

The decompiled abstract class from the library looks like this:

public abstract class APIGatewayRequestHandler<T> public constructor() : com.amazonaws.services.lambda.runtime.RequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent, T> {
    public abstract fun handleAPIGatewayRequest(input: com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent, context: com.amazonaws.services.lambda.runtime.Context?): T

    public open fun handleRequest(input: com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent?, context: com.amazonaws.services.lambda.runtime.Context?): T {
        /* compiled code */
    }
}

I get the following error:

Class 'GetWelcomeMessageHandler' is not abstract and does not implement abstract base class member
public abstract fun handleAPIGatewayRequest(input: APIGatewayProxyRequestEvent, context: Context?): WelcomeMessage
like image 355
Ken Avatar asked Jun 06 '18 04:06

Ken


Video Answer


1 Answers

I think you're just missing some override keywords. Namely, your abstract class should have it on the handleRequest method:

public abstract class APIGatewayRequestHandler<T> public constructor() : com.amazonaws.services.lambda.runtime.RequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent, T> {
    public abstract fun handleAPIGatewayRequest(input: com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent, context: com.amazonaws.services.lambda.runtime.Context?): T

    public override fun handleRequest(input: com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent?, context: com.amazonaws.services.lambda.runtime.Context?): T {
        /* compiled code */
    }
}

And then your GetWelcomeMessageHandler should have it on its handleAPIGatewayRequest method:

class GetWelcomeMessageHandler : APIGatewayRequestHandler<WelcomeMessage>() { // <-- This curly brace was also missing
    override fun handleAPIGatewayRequest(input: com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent, context: com.amazonaws.services.lambda.runtime.Context?): WelcomeMessage {
        return WelcomeMessage()
    }
}
like image 54
zsmb13 Avatar answered Oct 03 '22 21:10

zsmb13