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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:44:16+00:00 2026-05-23T14:44:16+00:00

In Scala, you can define package objects . It seems thus that you can

  • 0

In Scala, you can define package objects. It seems thus that you can access that package object by writing the package name, and then `package`:

// file package.scala in src/com

package com
package object test {
  val Version = 2
}

// file Test.scala in src/test

package test
object Test {
  def main(args: Array[String]) {
    val p = com.test.`package`          // get ref on package object
    val v1 = com.test.`package`.Version // (1) get val
    val v2 = com.test.Version           // (2) get val
  }
}

What is the difference between (1) and (2)? In some cases, I’ve had to write the extra `package` for my code to run. Should there be a difference or is it a compiler bug?

Moreover, what does e.g. this line mean, in Predef.scala?

scala.`package`   // to force scala package object to be seen.
  • 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-23T14:44:17+00:00Added an answer on May 23, 2026 at 2:44 pm

    Just a blind guess: The line

    scala.`package`
    

    results in a simple getstatic (the package object code) followed by pop. So it is doing nothing more but initialising the package object if it wasn’t already initialised before.

    So my guess is that in Predef.scala you cannot be sure (or it may be definite that it has not happened) that the package object has been initialised already. Most other modules may implicitly depend on Predef being loaded, so these modules cannot just be initialised blindly. Therefore one needs to ensure this by including the module/package/object explicitly in Predef. Same is done for the List module and StringBuilder. So, it might just be an initialisation order thing.

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

Sidebar

Related Questions

Consider the file bug.scala : package sandbox object Foo { implicit def stringToInt(s: String)
I'm learning Scala and there is a thing that I can't find out about
(Yes I know I can call Java code from Scala; but that is pointless;
In Scala, I can define structural types as follows: type Pressable = { def
I'm new to scala, and what I'm learning is tuple . I can define
In Scala we can define the type-level identity function for lower-kinded types like so,
As far as I understand, in Scala we can define a function with no
I have a scala object defined like the following: package com.example object Foo {
I can define a variable (by var ) that is immutable: var x =
How can I create a node in Scala without using literals? What I need

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.