Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7978029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:22:40+00:00 2026-06-04T09:22:40+00:00

I have two abstract classes which will hold references to each other.How / can

  • 0

I have two abstract classes which will hold references to each other.How / can I type bound the type members so as the types of HexT in the SideT members of the derived Hex classes will always be the derived Hex class? so for a derived class HexA it is guaranteed that: HexA#SideT#HexT = HexA

And similarly that the types of SideT in the HexT members of all the derived Side classes will be the derived Side Class: SideB#HexT#SideT = SideB

I’m using Scala for Eclipse 2.1.0.M1 with Eclipse 3.7.2 All Classes are in separate files. The following compiles OK but doesn’t guarantee what I want:

abstract class Hex { type SideT <: Side {type HexT <= Hex } }
abstract class Side { type HexT <: Hex {type SideT <= side } }
class HexC() extends Hex() { type SideT = SideC }
class SideC extends Side { type HexT = HexC }

But the following won’t compile in the derived implementations:

abstract class Hex{type SideT <: Side {type HexT = this.type}}
abstract class Side{type HexT <: Hex {type SideT = this.type}}
class HexC() extends Hex(){
  type SideT = SideC //This won't compile
}
class SideC extends Side {
  type HexT = HexC //this won't compile
}

Is this correct? Should this compile?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:22:42+00:00Added an answer on June 4, 2026 at 9:22 am

    How about this?

    abstract class Hex {
      type SideT <: Side
    }
    
    abstract class Side {
      type HexT <: Hex
    }
    
    class HexC extends Hex {
      type SideT = SideC
    }
    
    class SideC extends Side {
      type HexT = HexC
    }
    
    val evidence1 = implicitly[SideC#HexT =:= HexC]
    val evidence2 = implicitly[SideC#HexT#SideT =:= SideC]
    

    Or with an encapsulating trait for the domain:

    trait abstractDomain {
      type SideT <: Side
      type HexT <: Hex
    
      abstract class Hex
      abstract class Side
    }
    
    object domain extends abstractDomain {
      type SideT = SideC
      type HexT = HexC
    
      class HexC extends Hex
      class SideC extends Side
    }
    

    Or with type parameters:

    abstract class Hex[HexT <: Hex[HexT, SideT], SideT <: Side[HexT, SideT]]
    abstract class Side[HexT <: Hex[HexT, SideT], SideT <: Side[HexT, SideT]]
    
    class HexC extends Hex[HexC, SideC]
    class SideC extends Side[HexC, SideC]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an abstract class Airplane, and two classes PassengerAirplane and CargoAirplane, which extend
I have an abstract class MainClass which composes Animal class. I derive two classes
Can I extend a PHP class from two classes, one of which is abstract
In my c# project, I have two abstract generic parent classes which then have
I have two classes that are derived from an abstract generic class, which is
Consider the following example. I have an interface MyInterface, and then two abstract classes
I have a two generic abstract types: Entity and Association . Let's say Entity
I have an abstract entity called Block which contains two attributes: column and order
I have two application that need to talk to each other. App1 needs to
I have two classes which represent a special kind of numeric value. Let's call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.