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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:26:30+00:00 2026-05-23T21:26:30+00:00

In Scala, the syntax for selecting a type from a class is different from

  • 0

In Scala, the syntax for selecting a type from a class is different from that of selecting anything else from a class. In that the former uses a hash as the selection operator instead of a dot. Why is that?

Example: If we have a class like so…

class Example {
    type Foo = String
}

Why do we select the type from the class like this…

val example:Example#Foo = "1"

instead of like this?

val example:Example.Foo = "1"
  • 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-23T21:26:30+00:00Added an answer on May 23, 2026 at 9:26 pm

    Example#Foo is called a type projection and will match any type Foo of any enclosing instance of type Example. If you write a type Example.Foo, the compiler will look for the value (and not type) called Example and will refer to its enclosing Foo type only. This is often used in the context of singleton objects.

    For instance:

    object MyEnum extends Enumeration {
      val EnumValue = Value
    }
    
    val e: MyEnum.Value = MyEnum.EnumValue
    

    If Scala used . for type projections, this would lead to confusion because the preceding identifier could be interpreted either as a type or as a value… Hence the #. Note that, as @kassens writes, Java only has type projections in that respect.

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

Sidebar

Related Questions

Does Scala have a version of Rubys' each_slice from the Array class?
Does Scala provide a built-in class, utility, syntax, or other mechanism for converting (by
Is there a Scala library that parses Scala and creates an Abstract Syntax Tree
I want to write a function that works on any Scala type with a
I encountered this syntax in someone else's Scala code, and don't remember reading about
Java's Foo.class as well Scala's classOf[Foo] literal class syntax return a reflective view about
I think Scala goes too far from simplicity, like its syntax. For example Martin
In Scala, is it possible to get the string representation of a type at
In Scala, if I have a simple class as follows: val calc = actor
I'm trying to learn Scala and tried to write a sequence comprehension that extracts

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.