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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:05:21+00:00 2026-05-26T18:05:21+00:00

I understand the use for explicitly typed self-references : trait T { self :

  • 0

I understand the use for explicitly typed self-references:

trait T {
  self : T2 =>
  ...
}

In the body, self is an alias for this but has the more precise type T with T2.

Now, I’ve seen this in code:

trait T {
  self =>
  ...
}

That is, an explicit self reference with no additional type information. In this configuration, is there any situation in which self is not just an alias for this?

  • 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-26T18:05:21+00:00Added an answer on May 26, 2026 at 6:05 pm

    It is an alias for this.

    Your first example is useful for ensuring that the trait has been mixed in to an appropriate type, and makes those methods available.

    The second example is useful when you have inner classes with naming conflicts, to make the outer scope visible. For example:

    trait U {
      self =>
      val name = "outer"
      val b = new AnyRef {
        val name = "inner"
        println(name)
        println(this.name)
        println(self.name)
      }
    }
    

    Then new AnyRef with U prints

    inner
    inner
    outer
    

    “self” is not a special keyword – you can use “bananas =>” or whatever you like, but it’s often used by convention.

    This crops up quite a bit in Swing, where you make a lot on inner classes (textboxes within scrollpanes, etc), which usually have many methods with the same names as the outer classes.

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

Sidebar

Related Questions

I have this code. In main I want use type conversion, but with using
I can understand the use for one level of namespaces. But 3 levels of
I'm trying to understand when to use self.method_name vs. when to use Classname.method_name. In
I understand the use of the explicit keyword to avoid the implicit type conversions
I know this has been discussed ad nauseum...but I have an issue with the
This question is meant to apply to interfaces in general, but I'll use AS3/Flex
This isn't exactly the definition of implicit type conversion, but I'm curious how many
I want to understand the use of xargs man in Rampion's code : screen
I don't really understand the use and concept of an Intent. I DO understand
I am learning Django and I am trying to understand the use of models.py

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.