score:0
this is indeed unfortunate, and also happens in scala 2.9.2; you need to add the type there, though, so it's val x: x = new x(x)
. i think the compiler should clearly reject this as it can't succeed with eager argument v
.
i don't know what your exact scenario is, but it seems to be a data structure. maybe an approach like the following works for you
trait top
trait x extends top { def v: top }
object toploop extends x { def v: top = this }
class y( x: x ) extends top { def v: top = x }
if you want to use pattern matching, you can furthermore add sealed
to the traits and case
to the object and class.
score:5
lung,
how did your code with lazy and call-by-name look like? it works for me like this:
class top
class x(_v: => top) extends top {
lazy val v = _v
}
scala> lazy val x: x = new x(x)
x: x = <lazy>
scala> x.v
res3: top = x@422d15ad
Source: stackoverflow.com
Related Query
- self reference value
- How can a parameter's default value reference another parameter?
- Forward reference extends over definition of value shapes
- How to assign reference instead of value in Scala?
- When using shapeless.Generic, how to avoid the error 'super constructor cannot be passed a self reference unless parameter is declared by-name'?
- Reference Scala constructor args in default value
- Forward reference extends over definition of value problem
- Function reference as implicit parameter with default value not as expected
- scala assignment of value vs. reference types
- How does a lazy val solve forward reference extends over definition of value in scala
- scala closure - force bind to value not reference
- How to resolve self reference in this case?
- Reference to self type in parameterized trait
- "Forward reference extends over definition value exp" when using an abstract class with case classes of a Scala tutorial
- Reference field of object using string value scala macro
- Are parameters of self reference only available in the specific trait?
- Reference to anonymous value in Scala
- Compiler error while converting java Exception code to scala using intercept : ''forward reference extends over definition of value exception'
- How to debug the error "Class file needed by X is missing. reference value Y of package Z refers to nonexisting symbol" in Scala?
- What can I write after self reference arrow?
- Scala Errors- forward reference extends over definition of value
- forward reference extends over definition of value
- Unable to make reference to object in build.sbt, "error: not found: value hooks"
- Spark use self reference in calculation for column
- Extend class, define function parameter in subclass body? super constructor cannot be passed a self reference unless parameter is declared by-name
- Super constructor cannot be passed a self reference unless parameter is declared by-name
- How to Pass self reference from ActorSystem in Akka Typed
- Call by name vs call by value in Scala, clarification needed
- Difference between this and self in self-type annotations?
- How to check whether key or value exist in Map?
More Query from same tag
- IOException during splitting java.util.concurrent.ExecutionException: java.io.FileNotFoundException when loading HFile to HBase
- How to create a map from a RDD[String] using scala?
- How to properly validate and transform a json in play scala?
- SQLContext implicits
- Loop through list to call different functions
- How to filter methods by return type with scala reflection?
- Spark Join: analysis exception reference is ambiguous
- stuck at command "sbt compile" in docker ubuntu
- Choice of implicit conversion location with a block
- Scala: Select following sibling in xml
- execute a "release" command from inside a task in sbt
- Html Parsing vs. Regex
- Reading a large file in functional scala
- Getting type class instance through a parent type
- What exactly does def foo[A,B] mean? Type shadowing
- Type casting using type parameter
- import class priority in scala vs java
- How do I use Unix domain sockets from Java/Scala?
- Scala looping through an object
- explode an spark array column to multiple columns sparksql
- Why does the Spark DataFrame conversion to RDD require a full re-mapping?
- scala 2.8 implict java collections conversions
- Scala - Function's implicit return type
- Reading empty files with scala
- Mixing type parameters and abstract types in scala
- How to get a single defined element of a Coproduct instance?
- reading json file using jackson library in scala language
- How to split a line of text and append that line to each element in Scala/Spark
- find list of classes and custom annotations
- Unit test always returns scala match error null or null pointer exception