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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:16:47+00:00 2026-06-04T22:16:47+00:00

Is there any relationship between this aliasing and self type ? Is this aliasing

  • 0

Is there any relationship between this aliasing and self type?
Is this aliasing a special case of self type?
In programming in scala 2nd P776, the author said:

abstract class Parser[+T] extends … { p =>

You saw syntax like this in Section 29.4, where it was used to give a
self type to a trait.

but, the syntax for self type doesn’t look like this, it’s like:

this:SomeAssumedType =>

And another question is why this aliasing is useful? I can’t see there’s any sense to give this reference an alias, because it’s already a conventional alias for the current object reference, however in the Play framework source code, I saw lots of codes (especially, the anorm part) like:

trait RowParser[+A] extends (Row => SqlResult[A]) {

parent =>

Why does this make sense?

  • 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-04T22:16:48+00:00Added an answer on June 4, 2026 at 10:16 pm

    You can have a self-type and this aliasing at the same time:

    abstract class Parser[+T] { p: SomeAssumedType => … }
    

    If you don’t include a type ascription, Scala will assume that the type of the variable is the type of the surrounding class, thus giving you a simple alias for this.

    If you keep the name this with the ascription, then Scala expects you to initialise this class in a way that the ascription can be fulfilled.

    As for the this aliasing. Here’s the situation in which this is needed:

    object OuterObject { outer =>
      val member = "outer"
      object InnerObject {
        val member = "inner"
        val ref1 = member
        val ref2 = this.member
        val ref3 = outer.member
    
        def method1 = {
          val member = "method"
          member
        }
        def method2 = {
          val member = "method"
          this.member
        }
        def method3 = {
          val member = "method"
          outer.member
        }
      }
    }
    
    scala> OuterObject.InnerObject.ref1
    res1: java.lang.String = inner
    
    scala> OuterObject.InnerObject.ref2
    res2: java.lang.String = inner
    
    scala> OuterObject.InnerObject.ref3
    res3: java.lang.String = outer
    
    scala> OuterObject.InnerObject.method1
    res4: java.lang.String = method
    
    scala> OuterObject.InnerObject.method2
    res5: java.lang.String = inner
    
    scala> OuterObject.InnerObject.method3
    res6: java.lang.String = outer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any relationship between anonymous session ( where random identifier is generated for
I have a self-referencing many-to-many relationship between users and managers that looks like this:
What are the relationships between those (if there is any)? I know that ViewBag
I have entities Post and Tag , where there is a many-to-many relationship between
Is there any functionality in .Net or any Nuget package to put time in
Is there any extension or widget like the above image which i saw in
Is there any good resource for getting started with iOS development if you're an
Is there any function in clojure which calculates the boolean value of the given
is there any way to force the execution of task in Rake, even if
Is there any way to open a new window with a specified URL using

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.