score:8
I think this is what you want:
object Test {
println("This does not print!")
add(5, 6)
println("This however prints!")
add(5, 6)
def add(a: Int, b: Int): Int = a + b
}
How the worksheet works is, that if you define an object and nothing defined outside the object
scope, it will execute it as Test extends App
. Which is what the intellij page displays
If you have any statement outside the object
scope, it is then treated as any other object
and compiler will initialize it like anything else. This is what you are experiencing.
score:9
The scala worksheet executes the contents of the object test{....} if all the code is inside that object. If there is some code outside the object, it will just define that Test object (and not run it).
object Test {
println("This does not print!")
def add(a: Int, b: Int): Int = {print("Sum:" + a + b); a + b}
add(2, 2)
}
// defined the above Test object
Test // executes the Test object
score:15
I was able to evaluate the Scala work sheet by changing the Scala worksheet settings.
- change run type to plain (original it was REPL)
You can get to settings by clicking the settings icon on the Scala worksheet.
Source: stackoverflow.com
Related Query
- Scala worksheet does not evaluate object in IntelliJ IDEA 2016.2
- IntelliJ IDEA Hotkey for comment does not work with Scala
- Scala worksheet can not resolve class name - IntelliJ IDEA
- Intellij does not recognize code changes in scala main object
- Cannot get Scala Worksheet to evaluate inside of an object on Intellij
- Scala Compiler not found in Intellij IDEA 11 with Play 2.0 project
- IntelliJ Idea Scala files not available in 'New' context menu
- IntelliJ IDEA w/ Scala Plugin not finding scala.concurrent
- Scala worksheet not working in Intellij
- Intellij does not recognize Scala List operator
- Getting "Internal error: Scala instance doesn't exist or is invalid" when trying to run a worksheet in IntelliJ IDEA
- IntelliJ IDE does not detect Scala templates properly
- Scala sbt assembly jar does not work (class implementation not found) but code works when through IntelliJ
- scala project does not work in intellij
- Eclipse Scala Worksheet error value is not a member of object
- "Error:scalac: Error: object VolatileFloatRef does not have a member create" when using Scala 2.11.8 SDK
- Scala - IntelliJ IDEA Error: Could not find or load main class
- Cannot make Spark run inside a scala worksheet in Intellij Idea
- Idea 13 and Gradle when trying to use scala-compiler in the Scala facets does not find scala-library
- Intellij idea scala worksheet Internal error: java.lang.NoClassDefFoundError: scala/Serializable
- Scala plugin for IntelliJ IDEA 10 not detecting simple errors?
- Stop IntelliJ IDEA Scala worksheet from removing blank lines
- Scala worksheet evaluation results not showing up in Intellij
- Could not find implicit value inside companion object in Scala Worksheet
- Scala IntelliJ 2016 not running code
- Flink does not allow Immutable style setters for POJO object when using scala case classes
- Why does Scala compilation get stuck in IntelliJ IDEA 13.1.3?
- IntelliJ IDEA 12.0 Scala worksheet errors under Standard User account but works under Administrator
- My Intellij worksheet does not print out the number sequence defined in Thread.run, but sbt does
- Scala project with maven in IntelliJ does not compile
More Query from same tag
- Google Sign in error 403 - Project marked for deletion
- Conditional application of `filter`/`where` to a Spark `Dataset`/`Dataframe`
- Spark SQL - Column is available after drop
- If trait A[+T] extends B, should I be able to pass classes of type A[T] where B is needed?
- Efficient processing of custom data by actors
- Gathering Post Values on Form Error in the Play Framework using Scala
- SBT rpm:package-bin fails with config not found error
- How to provide alternative implementation of abstract interface in Scala?
- Debugging expression evaluation
- Spark job fails with org.apache.spark.shuffle.FetchFailedException exception
- Explanation needed scala fixedpoint from coursera
- What is going wrong with `unionAll` of Spark `DataFrame`?
- Scala read two integers at the same time error
- How to print elements of particular RDD partition in Spark?
- How does foldLeft in Scala work on DataFrame?
- Processing Future Comprehension Scala
- Dealing with errors using idiomatic Scala
- Play framework controller test - No implementation for <classname> was bound
- not found: value udf error
- Is it possible to override form helpers?
- Apache Spark - UDF doesn't seem to work with spark-submit
- sbt local m2 repository
- Scala - Constructs map from two lists at initialization
- How to form select * from query in salesforce by using scala+spark connector?
- How to perform Set transformations on RDD's with different number of columns?
- Two URLClassLoaders with the same classpath with different behaviour
- How to move selected columns of a DataFrame to the end of it (re arranging the column positions)?
- DAG of Spark Sort application spanning two jobs
- What to import to make < work for jodatime in Scala
- scodec - Method too large