[SOLVED]What's the meaning of # in scala?

I’m confused when I was reading the Kafka Code.The code is shown as follow.

def handleRequest[Req <: AsyncRequest](request: Req): Req#Response = {
    handleRequests(Seq(request)).head
 }

sealed trait AsyncRequest {
  /**
   * This type member allows us to define methods that take requests and return responses with the correct types.
   * See ``ZooKeeperClient.handleRequests`` for example.
   */
  type Response <: AsyncResponse
  def path: String
  def ctx: Option[Any]
}

case class CreateRequest(path: String, data: Array[Byte], acl: Seq[ACL], createMode: CreateMode,
                         ctx: Option[Any] = None) extends AsyncRequest {
  type Response = CreateResponse
}

sealed abstract class AsyncResponse {
  def resultCode: Code
  def path: String
  def ctx: Option[Any]
  ...
}

case class CreateResponse(resultCode: Code, path: String, ctx: Option[Any], name: String,
                          metadata: ResponseMetadata) extends AsyncResponse

My question is what’s the meaning of “Req#Response”?

Is a type projection, which is an unsound feature of the language which was dropped in Scala 3, for details check: 𝐖ell-𝚻yped 𝐑eflections

Ideally, it should have been request.Response but who know why they didn’t use that.

3 Likes

Thank you for replying. I get it now!