IntelliJ gives me the warning that "abstract value in trait may cause errors during initialization" - as shown in the picture below.
- What does this mean ?
- Should I take this warning seriously ?
- Should I use
def
-s instead oflazy val
-s ? - Are they not the same in this case ? Since we are talking here about dependency injection, which creates a static - possibly cyclical - object graph.
- But ! because the
lazy
modifier is there, it does not matter if the graph is cyclical or not. Right ? - The values themselves will simply behave as they were a memoized function right ?
- Since we are talking about references here (in a static object graph) where references are directed edges and objects are nodes, what's the problem here ?
- Could you please give an example where using
lazy val
-s instead ofdef
-s can cause problems during initialization ?
Thank you for reading :)
The whole codebase is on github.
This is the particular line that is problematic (on github).
I also copy paste the problematic code here:
trait EntityMarshallers[V<:EntityValue[V]]{
implicit lazy val decoderEntityV: Decoder[Entity[V]]
implicit lazy val encoderEntityV: Encoder[Entity[V]]
implicit lazy val _encoderV: Encoder[V]
implicit lazy val classTag: ClassTag[V]
}
This is the IntelliJ warning :