BigDataScholar BigDataScholar - 19 days ago 6
Scala Question

Illegal inheritance, superclass X not a subclass of the superclass Y of the mixin trait Z - Scala

I am trying to execute a akka-http which is a scala program. My KISS code is as follows:-

import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpRequest, HttpResponse}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.directives.BasicDirectives
import com.typesafe.config.ConfigFactory

object MyBoot02 extends SprayCanBoot02 with RestInterface02 with App {


abstract class SprayCanBoot02 {

val config = ConfigFactory.load()
val host = config.getString("")
val port = config.getInt("http.port")

implicit val system = ActorSystem("My-ActorSystem")
implicit val executionContext = system.dispatcher
implicit val materializer = ActorMaterializer()
//implicit val timeout = Timeout(10 seconds)

implicit val routes: Flow[HttpRequest, HttpResponse, Any]

Http().bindAndHandle(routes, host, port) map {
binding => println(s"The binding local address is ${binding.localAddress}")

trait RestInterface02 extends AncileDemoGateway02 with Resource02 {

implicit val routes = questionroutes
val buildMetadataConfig = "this is a build metadata route"

trait Resource02 extends QuestionResource02

trait QuestionResource02 {
val questionroutes = {
path("hi") {
get {
complete("questionairre created")

class AncileDemoGateway02 {

The error that I get is because of how I am wiring stuff when trying to execute MyBoot02. The error is as follows:

Error:(58, 41) illegal inheritance; superclass SprayCanBoot is not a
subclass of the superclass AncileDemoGateway of the mixin trait
RestInterface object MyBoot extends SprayCanBoot with RestInterface
with App

Why does the error state 'SprayCanBoot is not a subclass of the superclass AncileDemoGateway'. In my code SprayCanBoot and AncileDemoGateway are 2 separate entities then why such an error?



Unfortunately, for some mysterious reason, that's probably inherited from the wonderful design of Java, you cannot extend more than one class either directly or indirectly. It is possible to mix in as many traits as you want, but you can only have one superclass in the hierarchy (ok, technically, you can have more than one, but they all must be extending each other - that's why your error message is complaining about SprayBoot not being a subclass).

In your case, you are extending SprayCanBoot02, which is a class, and also RestInterface02, that extends AncileDemoGateway02, which is also a class. So MyBoot02 is trying to extend two different classes at once, which is illegal.

Making AncileDemoGateway02 a trait should fix the error.