score:11
this happens because of how you used the app trait. the app trait uses the delayedinit feature which changes how the class body (including field initialization) is executed. the app trait includes a main method which executes the class body after binding the args field to the arguments to the program. since you have overridden main this initialization is not happening. you should not provide a main method when using the app trait. you should either put the application code directly in the class body or not inherit from the app trait.
score:1
try
lazy val x = "hello world"
that should give you the results you're expecting.
score:1
you are not support to have a main
method on an object extending app
. if you do override it, you'd better understand how, exactly, delayedinit
works. in particular, objects extending app
do not have static initialization -- that's the whole point of app
.
Source: stackoverflow.com
Related Query
- In Scala static value initialization does not appear to be happening before the main method is called
- getOrElse for an Option(null) does not return a None type or the default value when null in Scala
- Why does Haskell's foldr NOT stackoverflow while the same Scala implementation does?
- Why does this Scala function compile when the argument does not conform to the type constraint?
- Why does Scala choose the type 'Product' for 'for' expressions involving Either and value definitions
- Why does Scala warn about type erasure in the first case but not the second?
- VectorAssembler does not support the StringType type scala spark convert
- Scala Option? Why does Some not inherit AnyVal and why is it not a value type?
- Why does Scala maintain the type of collection not return Iterable (as in .Net)?
- Why does the Scala compiler say that copy is not a member of my case class?
- Why does using the '~' operator in scala give me a negative value
- scala does not warn about unused computation or value
- Renaming a .scala file in Scala IDE does not rename the class
- Scala with spark - "javax.servlet.ServletRegistration"'s signer information does not match signer information of other classes in the same package
- Why the scala :_* to expand a Seq into variable-length argument list does not work in this case?
- Idea 13 and Gradle when trying to use scala-compiler in the Scala facets does not find scala-library
- How does the initialization of classes in Scala work?
- Why does the same scala code work OK in command line while not in Intellij?
- Why does Scala not infer the type parameters when pattern matching with @
- Why this simple Scala for comprehension does not execute the futures?
- Error: value is not a member of object using Scala on the shell
- Why does the Scala compiler give "value registerKryoClasses is not a member of org.apache.spark.SparkConf" for Spark 1.4?
- Why `Numeric` in the Scala standard library does not have a `maxValue`?
- Does Scala have a value restriction like ML, if not then why?
- Why does mapping over a Scala enumeration's ValueSet not change the type of the values?
- Why does one of these statements compile in Scala but not the other?
- Logging the value of a future before returning it in Scala
- Why does drop() method in Scala allow negative value and does not throw error?
- Why the following Scala code does not compile unless explicit type parameters are added?
- Why does the `is not a member of` error come while creating a list in scala using the :: operator
More Query from same tag
- Disable SSL with Scala Dispatch Library
- How to take the logarithm of an RDD in Spark (Scala)
- Scala Spark group as per value change
- Calling type classes by using the type from a variable
- Get name of assigned variable at runtime in Scala
- Instantiate a type based on json and metadata using lift-json
- How to migrate to Gatling 2.2 from 2.1.7
- Using Gradle, how can I list just the JSON library of the Play framework as a dependency?
- How to package multimodule library as one jar
- Functions are contravariant in their argument types and co-variant in their return types
- sbt ignoring library dependency
- Using InputStreamEntity for buidling a http put request with httpclient won't work unless I pass the content length explicitely
- sbt subproject aggregation and dependency behavior
- How do I get map item with Option[Long]?
- Trying to write a generic filter function in Scala
- Have a mutable sequence or always delete and create a new immutable sequence?
- Handling auto inc columns in Oracle via slick
- Using Typesafe Config's ConfigFactory to set key setting in build.sbt?
- How to deploy my spray API into production?
- Spark Context not Serializable?
- What are Spark UDFS?
- Scala call-by-name constructor parameter in implicit class
- Heterogeneous arguments in a Scala function
- Scala project won't compile with Bouncy Castle as dependency
- cannot select a specific column for ReduceByKey operation Spark
- Getting context using AnnotationConfigApplicationContext in Akka Actor
- Dependency injection with Akka
- Memory visibility in Fork-join
- Scala - state while looping through a list
- What would be the best practice of Scala to have a method accept two different models