score:4
Accepted answer
Just override it with a lazy val
:
trait A { val valueA: Int = 100500 }
trait B {
val valueB: Int
println(valueB)
}
class C extends A with B { lazy val valueB = valueA }
new C
// prints 100500
score:1
There are likely alternative ways to write the tests without having to use early initialisers (which are deprecated), for example the following might give some ideas
class FixturesSpec extends FlatSpec with Matchers {
case class FixtureA(x: Int = 42)
case class FixtureB(y: Int = -11)
trait CommonFixture {
val commonCaseValue: Int = 1
}
trait SpecialCaseFixture {
val specialCaseValue: Int
}
"traits" should "be fixtures" in new SpecialCaseFixture with CommonFixture {
override val specialCaseValue = commonCaseValue
specialCaseValue should be (1)
}
"case classes" should "be fixtures" in new FixtureA(FixtureB().y) {
x should be (-11)
}
}
Source: stackoverflow.com
Related Query
- Scala intermediate early initializer
- scala early initializer with var cause ClassCastException
- scala observable unify observable with a sequence without intermediate datastructure update
- How to assign name to intermediate whilst pattern matching in Scala
- How to early return in Scala
- Early return from a Scala constructor
- Scala for comprehensions and flatMap / map intermediate results
- scala (package) object decompiled as java - static initializer containing "new ();" - what is that?
- How to store the intermediate results of a scala match expression into a list?
- Scala data structures: chain of operations (such as mapValues, filter ...) and intermediate results
- Scala `map` but exit early on `Failure`
- Early initializer `new {} with SomeTrait` fails
- Can I store an intermediate result in an Scala case match?
- Scala: Example use for early definition / early initializer / pre-initialized fields
- How to make a new List in Scala from previous one by calculating all intermediate value?
- Scala parser combinators: how to return the content of intermediate parsers when combined with "into"?
- Scala inference : fail on 1 evaluation, success with intermediate val
- How to create param for superclass constructor without early initialiser in Scala
- Scala trait, superclass and early definition syntax
- Why do we need intermediate newBuilder in inits method of Scala List
- Scala future recursion returning early
- Scala - construction order and early definition syntax
- return early in Unit-returning function in Scala
- Specification of Scala compiler's intermediate code
- Early return from a for loop in Scala
- Avoid having to convert to an intermediate data-structure before calling .toMap in Scala
- Scala Akka code terminating early
- Is the Scala 2.8 collections library a case of "the longest suicide note in history"?
- Difference between object and class in Scala
- Scala vs. Groovy vs. Clojure
More Query from same tag
- How to produce list of words from the text file in scala
- Why implicitConversions is required for implicit defs but not classes?
- How to find out if a Node has children
- HOW TO Find by Object ID on MongoDB with Casbah?
- Scala/akka Pattern Matching a Sequence of Futures pipelined to a actor message
- What is the underscore character used for in Scala?
- Using the RootProject feature of sbt to do something other than 'sbt compile'
- How do I list all files in a subdirectory in scala?
- NoSuchMethodError on apache spark. Sbt dispatcher library not found
- Task "assembly" fails with "[error] (assembly) java.nio.file.InvalidPathException: Trailing char < > at index 121"
- Calculate the number of occurrences of letters, and put the dictionaries in the list
- Why does complete'ing requests where JavaUUID is used lead to compilation error?
- Text extraction using spark and scala
- Twitter data from spark
- How to eliminate error underlining in IntelliJ 14.0.3 for Play 2.3.7 application?
- How to parse JsonArray in Scala and writing them in a DataFrame?
- Scala preserve type parameter of case class object upon copying
- Scala: replace char at position i in String
- Joda Time: Convert UTC to local
- Scala streaming a live/growing file
- Binary distributions of old (1.0 - 2.5) versions of Scala?
- Idiomatic way of prepending Option[A] to Option[List[A]]
- Can I create a proto jar for scalaVersion 2.11/2.12 and use it within the same sbt under different sub-project?
- Why if I extend the App trait in Scala, I override the main method?
- When is it okay to use "var" in Scala?
- scala class names in configuration map
- Using Play for Scala, how do I read in JSON body {a=...,b=...,c...} from POST request?
- get value from right resut scala
- Play 2.5.3 - Running Scalatest on console, getting java.lang.NoClassDefFoundError: Could not initialize class play.api.Play$
- how to use pattern match get a nonEmpty list in scala?