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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:06:52+00:00 2026-06-06T18:06:52+00:00

Possible Duplicate: What is the difference between scala self-types and trait subclasses? I understand

  • 0

Possible Duplicate:
What is the difference between scala self-types and trait subclasses?

I understand a self-annotation as a promise to the compiler, where the programmer manifests that a trait will be mixin with the annotated one. For example:

scala> trait X
defined trait X

scala> trait Y { this: X => }
defined trait Y

scala> new Y {}
<console>:10: error: illegal inheritance;
self-type Y does not conform to Y's selftype Y with X
              new Y {}
                  ^

scala> new Y with X {}
res1: Y with X = $anon$1@1125a40

In the previous example, the third expression failed because we did not set a valid X to the new instance. Obviously, the last one works nice. So far, so good. And now, let’s see another example which involves an object.

scala> object Z { this: X => }
defined module Z

I understand the object is being instantiated failing with the X promise (we are creating an instance now with a future promise!), as represented in the next lines, where the traits have been slightly modified:

scala> trait X { class X1 }
defined trait X

scala> trait Y { this: X => new X1 }
defined trait Y

scala> object Z { this: X => new X1 }
<console>:8: error: not found: type X1
       object Z { this: X => new X1 }
                                 ^

So, what does the object self-annotation imply?

  • 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-06T18:06:54+00:00Added an answer on June 6, 2026 at 6:06 pm

    In fact, you can do the same thing with classes – add a self-type which is not inherited, but you won’t be able to instantiate such a class.

    Allowing singleton objects to have self types does not invalidate programs in any way – you simply won’t be able to call any of the methods of the self-type (or instantiate its inner classes) from within the singleton object, because it didn’t inherit the self-type.

    Nevertheless, it may be a bug, you may wish to file a bug.

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

Sidebar

Related Questions

Possible Duplicate: difference between throw and throw new Exception() I'm a programmer working on
Possible Duplicate: Scala traits vs abstract classes What is the conceptual difference between abstract
Possible Duplicate: Difference between Covariance & Contra-variance I'm trying to understand what covariance and
Possible Duplicate: Difference between e.target and e.currentTarget I don't really understand the difference between
Possible Duplicate: Functions vs methods in Scala What is the difference between def foo
Possible Duplicate: Difference between a Structure and a Union in C I could understand
Possible Duplicate: difference between accessing a property via “propertyname” versus “self.propertyname” in objective-c? In
Possible Duplicate: Difference between (function(){})(); and function(){}(); I am trying to understand a few
Possible Duplicate: Difference Between Equals and == in which cases equals() works exactly like
Possible Duplicate: difference between abstraction and encapsulation? What is the difference between abstraction and

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.