Any idea while the compiler isn’t able to infer th...
# compiler
c
Any idea while the compiler isn’t able to infer that the
self-referential
vararg parameter passed on the constructor is a container and thus the given class is
constructible
? Current fix: Requires I make the parameter type nullable or otherwise suppress this warning.
d
Does
class GraphNode(val value: Int, val children: Array<GraphNode>)
work?
c
No it doesn’t. That requires me to pass an array when constructing every node or otherwise an empty array. Yikes!
There are several ways to go about this implementation. I was just wondering why the compiler isn’t able to infer that a vararg will result in a container type that can be empty.
@Dominaezzz I could modify your suggestion to this:
Copy code
class GraphNode(val value: Int, children: Array<GraphNode> = emptyArray())
d
SelfReferenceConstructorParameter
is an IDE warning, not compiler's (and it doesn't affect compilation) Look like there is a bug in corresponding inspection, so you can create a ticket at https://youtrack.jetbrains.com/issues/KT
c
Thanks for the clarification @dmitriy.novozhilov. Creating a ticket on this.
👍 1