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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:38:11+00:00 2026-06-08T15:38:11+00:00

I am trying to understand the 4th rule on Precedence on Bindings on page

  • 0

I am trying to understand the 4th rule on Precedence on Bindings on page 93 in Joshua Suareth’s book Scala in depth.

According to this rule:

definitions made available by a package clause not in the source file where the definition occurs have lowest precedence.

It is this rule that I intend to test.

So off I went and tried to follow Josh’s train of thought on Page 94. He creates a source file called externalbindings.scala and I did the same, with some changes to it as below

package com.att.scala

class extbindings {
  def showX(x: Int): Int = {
    x
  }

  object x1 {
    override def toString = "Externally bound obj object in com.att.scala"
  }
}

Next he asks us to create another file that will allow us to test the above rule. I created a file called precedence.scala:

package com.att.scala

class PrecedenceTest { //Josh has an object here instead of a class

  def testPrecedence(): Unit = { //Josh has main method instead of this
    testSamePackage()
    //testWildCardImport()
    //testExplicitImport()
    //testInlineDefinition()
  }

  println("First statement of Constructor")
  testPrecedence
  println("Last statement of Constructor")

  def testSamePackage() {
    val ext1 = new extbindings()
    val x = ext1.showX(100)
    println("x is "+x)
    println(obj1) // Eclipse complains here
  }
}

Now, Josh is able to print out the value of the object in his example by simply doing the <package-name>.<object-name>.testSamePackage method on the REPL.
His output is:

Externally bound x object in package test

In my versions, the files are in Eclipse and I have my embedded Scala interpreter.

Eclipse complains right here: println(obj), it says: not found value obj1

Am I doing something obviously wrong in setting up the test files?
I would like to be able to test the rule I mentioned above and get the output:

Externally bound obj object in package com.att.scala

  • 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-08T15:38:14+00:00Added an answer on June 8, 2026 at 3:38 pm

    I haven’t read the book, thus I’m not really sure if your code shows what the book wants to tell you.

    Nevertheless, the error message is correct. obj1 is not found because it doesn’t exist. In your code it is called x1. Because it is a member of extbindings you have to access it as a member of this class:

    println(ext1.x1)
    

    If x1 is defined outside of class extbinding, in scope of package com.att.scala, you can access it directly:

    println(x1)
    

    If it is defined in another package you have to put the package name before:

    println(com.att.scala2.x1)
    

    To simplify some things you can import x1:

    import ext1.x1
    println(x1)
    

    Finally a tip to improve your code: name types in UpperCamelCase: extbindings -> Extbindings, x1 -> X1

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

Sidebar

Related Questions

Trying to understand PNG format. Consider this PNG Image: The Image is taken from
Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults
Trying to understand Ruby a bit better, I ran into this code surfing the
Trying to understand the math of this code snippet. A token is provided which
Im trying to understand how class generics work and this bit just doesnt make
Trying to understand why this doesn't work. I keep getting the following errors: left
Trying to understand this binding process of the WPF. See the code at the
While trying to understand how a web server worked, I came accross this: //myfile.js
Trying to understand this open source app on github, it has a gem file:
After trying to understand why client code is not rendered in a page (injected

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.