am5255 am5255 - 15 days ago 5
Scala Question

Print out Scala worksheet results in interactive mode in IntelliJ

For some reason, intermediate values aren't being printed out in the REPL console (right hand side of the worksheet)

For instance, this is what I have:

object test {
val obj = new MyObject(1)
obj.value
}

class MyObject(x: Int) {
def value = x
}


In the REPL results, I only get the following:

defined module test
.
.
.
defined class MyObject


However, I don't get any of the intermediate results, such as when I evaluate
x.value


I would expect something like:

> MyObject@14254345
> 1


after
x.value


Any reason why this isn't printing out?

Answer

What ended up working for me in this case (and this might be particular to IntelliJ 14, since I've seen it working the other way in Eclipse) is I added the class inside the object block, like this:

object test {
  val obj = new MyObject(1)
  obj.value 

  class MyObject(x: Int) {
   def value = x
  }
}

This forced the REPL instance inside the worksheet to auto-evalute the result and print them out on the right hand side.

Comments