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

  • Home
  • SEARCH
  • 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 6589467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:10:44+00:00 2026-05-25T17:10:44+00:00

I have 2 related traits. Dao will be used be a class and DaoHelper

  • 0

I have 2 related traits. Dao will be used be a class and DaoHelper will be used by Dao’s companion object. I would like trait Dao to be able use functions defined in DaoHelper, the only way I could figure out how to do this is to define the companion trait as a val. However somehow companion expects its type to be D.this.T which I thought I has defined as a subtype of Doa. I am confused here. My apologies for the newb question, I come from a dynamic language background.

/test2.scala:14: overriding value companion in trait Dao of type Test.DaoHelper[D.this.T];
[error] value companion has incompatible type
[error] val companion = D

object Test extends App {

  trait Dao {
    type T <: Dao
    val companion: DaoHelper[T]
    def getHelpfulData = companion.help
  }

  trait DaoHelper[Dao] {
    val help = "Some helpful data"
  }

  class D extends Dao {
    val companion = D
  }

  object D extends DaoHelper[D]
}
  • 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-05-25T17:10:44+00:00Added an answer on May 25, 2026 at 5:10 pm

    companion has type DaoHelper[T], but T isn’t specified anywhere in D, so how would the compiler know it is supposed to be D in class D? You can fix it by overriding it in D.

    class D extends Dao {
      type T = D
      val companion = D
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several navigation related functions which I would like to have no depth
I have two related POCOs public class Parent { public Guid Id {get; set;}
Say we have the following two traits: trait Foo[A] { def howMany(xs: List[A]) =
What's the the connection between those Future-related class and traits in Scala, and why
I have two related entities, say @Entity public class Book { @ManyToOne Shelf shelf;
I have several related CVS projects, and I'd like to move them into subdirectories
I have two related questions one general and one specific to the project I'm
I have two related tables in my database: Page and Tag. One Page can
We have various related session variables for a complex page that has various things
I have question related to what is done in SMS application is if i'm

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.