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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:12:45+00:00 2026-05-19T10:12:45+00:00

I have a scenario where I have some objects that need to take in

  • 0

I have a scenario where I have some objects that need to take in references from each other. The only way I can get this to compile is to use lazy

class A(b:B)
class B(a:A)
lazy val a:A = new A(b)
lazy val b:B = new B(a)

I can do the same thing using some actors, and get it to compile also

    abstract class Message
    case class Message1 extends Message
    case class Message2 extends Message

    class Actor1(otherActor:Actor) extends Actor {
        def act() {
            loop {
                react {
                    case Message1 =>
                        println("received message1")
                        otherActor ! Message2
                    case _ =>
                }
            }
        }
    }

    class Actor2(otherActor:Actor) extends Actor {
        def act() {
            loop {
                react {
                    case Message2 =>
                        println("received message2")
                        otherActor ! Message1
                    case _ =>
                }
            }
        }
    }

    lazy val actor1:Actor = new Actor1(actor2)
    lazy val actor2:Actor = new Actor2(actor1)

However, when I add the following:

    actor1.start
    actor2.start
    actor1 ! Message1

I get the following error:

Exception in thread “main”
java.lang.NoClassDefFoundError:
com/fictitiousCompany/stackOverflowQuestion/Test
Caused by:
java.lang.ClassNotFoundException:
com.fictitiousCompany.stackOverflowQuestion.Test
at
java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at
java.security.AccessController.doPrivileged(Native
Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at
java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at
java.lang.ClassLoader.loadClass(ClassLoader.java:248)

I’m using the Scala Eclipse Plugin 2.8.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-19T10:12:46+00:00Added an answer on May 19, 2026 at 10:12 am

    Note that even your smaller example would have issues (in the REPL):

    {
    class A(b:B)
    class B(a:A)
    lazy val a:A = new A(b)
    lazy val b:B = new B(a)
    a
    }
    // causes stack overflow error
    

    As soon as a needs to be evaluated therefore constructed, it would require B, which requires A. In order for this to work a or b would have to finish being constructed.

    Using by-name parameters allows the smaller example to evaluate.

    {
    class A(b: => B)
    class B(a: => A)
    lazy val a:A = new A(b)
    lazy val b:B = new B(a)
    a
    }
    

    Note sure if that’ll work for your actor example as well.

    Edit: by name params worked locally on 2.8.0. I replaced case class with object to get rid of some deprecation warnings and added start methods on actor1, actor2 and kick the whole thing with actor1 ! Message1. Aside from this I haven’t used actor before, so I can’t comment more. Here is what I tested:

    import scala.actors._
    
    abstract class Message
    object Message1 extends Message
    object Message2 extends Message
    
    class Actor1(otherActor: => Actor) extends Actor {
    def act() {
        loop {
        react {
            case Message1 =>
            println("received message1")
            otherActor ! Message2
            case _ =>
        }
        }
    }
    }
    
    class Actor2(otherActor: => Actor) extends Actor {
    def act() {
        loop {
        react {
            case Message2 =>
            println("received message2")
            otherActor ! Message1
            case _ =>
        }
        }
    }
    }
    
    {
      lazy val actor1:Actor = new Actor1(actor2)
      lazy val actor2:Actor = new Actor2(actor1)
      actor1.start
      actor2.start
      actor1 ! Message1
    }
    

    Prints a bunch of:

    received message1
    received message2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the scenario I have a Grid with some TextBlock controls, each in a
Hi I need some help with the following scenario in php. I have a
I have a scenario where I need to upload a file from one web
How can I downcast a list of objects so that each of the objects
Here is the scenario: I have successfully bound two objects from a native ObjC
I have a scenario when I start 3..10 threads with ThreadPool. Each thread does
I have this scenario where I need data integrity in the physical database. For
I have a situation where I'm starting a number of objects that, when they
I'm bumbling my way through creating a Silverlight 3 application. I need some high
I'm working on a internal web application (only employees can log in) and 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.