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

16,386

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()
    }
}
Share:
16,386

Related videos on Youtube

Ken
Author by

Ken

Updated on September 15, 2022

Comments

  • Ken
    Ken over 1 year

    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
    
  • Ken
    Ken almost 6 years
    When I add "override" to GetWelcomeMessageHandler's handleAPIGatewayRequest method, I get the following error: Modifier 'override' is not applicable to 'top level function'
  • zsmb13
    zsmb13 almost 6 years
    Oh, I just realised you're also missing a { after the end of the GetWelcomeMessageHandler declaration. See the edit in my answer above.
  • Ken
    Ken almost 6 years
    That fixed the issue, allowed me to add override to the method. Thanks! The error message was very misleading
  • zsmb13
    zsmb13 almost 6 years
    Indeed, the one about a top level function was a much better one.