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 6838747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:38:03+00:00 2026-05-26T23:38:03+00:00

Given the abstract definitions of the Outer class and its Inner class I would

  • 0

Given the abstract definitions of the Outer class and its Inner class I would like to instantiate the concrete Inner1 class defined within Outer1 trait.

abstract class Outer {
  type Inner_Tp <: Inner;
  abstract class Inner {
    self: Inner_Tp =>
  }
}

trait Outer1 {
  self: Outer =>
  protected class Inner1 extends Inner {
    self: Inner_Tp =>
  }
  def Inner1() = new Inner1()
}

The Scala compiler prematurely terminates the compilation giving me the following error message: “error: class Inner1 cannot be instantiated because it does not conform to its self-type Outer1.this.Inner1 with Outer1.this.Inner_Tp”. Why?

After all the Inner1 class is defined within an abstract context being its Outer1 trait. I would like to postpone the definition of type Inner_Tp until the trait gets mixed into some concrete class.

  • 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-26T23:38:04+00:00Added an answer on May 26, 2026 at 11:38 pm

    For Inner1, the self-type says that it will always be instantiated together with the abstract type Inner_Tp. That’s a promise that is not fulfilled at the instantiation point: the type is only Inner1 instead of Inner1 with Inner_Tp.

    If you need to delay the definition of Inner_Tp, you also need to delay the creation of any instances that have it as a self-type. That is absolutely necessary, since you cannot produce a value of a type that you don’t know yet. So better leave the method abstract. You may refine the abstract type as well:

    trait Outer1 extends Outer {
       type Inner_Tp <: Inner1
       protected class Inner1 extends Inner
    
       def Inner1(): Inner_Tp
    }
    

    I’m not sure what you are after, but you may not need the self-types at all (I left them out for brevity already).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following entity definitions: @Entity class abstract A { Collection<A> parents; } @Entity
Given the follwing class - I would like to know which of the both
Given the following Scala definitions abstract class C { type T1 <: { def
Given the following model: class Project(models.Model): project_name = models.CharField(max_length=255) abstract = models.TextField(blank=True, null=True) full_description
Given an absolute or relative path (in a Unix-like system), I would like to
Given a abstract factory implementation: public class FooFactory : IFooFactory { public IFoo Create(object
Given this: abstract class ViewPresenterPair { type V <: View type P <: Presenter
Given the following code : public abstract class Participant { private String fullName; public
Given this example: abstract class Base { type Value } case object Foo extends
Given this highly simplified example: abstract class Animal { } class Dog : Animal

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.