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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:27:46+00:00 2026-06-13T17:27:46+00:00

object Initialization { def main(args: Array[String]): Unit = { val list = Traversable(1,2,4,5) //list.foreach(println)

  • 0
object Initialization {

  def main(args: Array[String]): Unit = {

    val list = Traversable(1,2,4,5)

    //list.foreach(println)

    println( list.getClass.getSimpleName )

  }

}

It prints $colon$colon, but I expected something like List. What does this obscure name mean?

  • 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-13T17:27:47+00:00Added an answer on June 13, 2026 at 5:27 pm

    That’s because List is a sealed superclass that is over case class :: and object Nil (see the known subclasses section under the List documentation). :: is pronounced cons, being named after the list cons operator in most traditional functional programming languages.

    Since your list head is actually an instance of the :: case class, and Scala uses name mangling to represent non-word class names on the JVM, you end up with $colon$colon when you use reflection to get the name.

    Update: I’m not exactly sure what you’re trying to use the class name for, but you might be able to use stringPrefix instead. It’s defined for anything extending GenTraversableLike, which will be pretty much every Scala collection type.

    If you’re trying to do control flow with the class name, you should probably try something else. Pattern matching would work nicely, e.g.:

    xs match {
      list: List[_] => // do list stuff
      set: Set[_] => // do set stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object that contains a array. On initialization of this object, the
object(stdClass)[1] public 'inbox' => array 0 => object(stdClass)[2] public 'from' => string '55512351' (length=8)
I have a class defined as class Conditional_Singleton(object): def __init__(self, condition=None): self.initialization = some_func_of(condition)
Doesn't object initialization outside of a constructor break encapsulation ? Given: class MyClass {
I have an object, that on initialization creates a serial GCD queue using dispatch_queue_create
object[] objs = new object[]{one,two,three}; Are the strings stored in the array as references
object[] objArray = new object[]{blah, 4, whatever}; foreach(var value in objArray) vs. foreach(object value
class A(object): def __init__(self, a, b, c): #super(A, self).__init__() super(self.__class__, self).__init__() class B(A): def
I do an object initialization as done in the code below: namespace PatternPractice {
Is it possible to use a lambda expression inside an object initialization expression? Please

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.