The following code does not compile:
var next: (A, A) = (null, n)
Error:
error: type mismatch;
found : Null(null)
required: A
var next: (A, A) = (null, n)
Also var next: (A, A) = ((null: A), n) fails with the same error.
Somehow I think it should compile.
I’m currently using the following code which seems to work:
var next: (A, A) = (null.asInstanceOf[A], n)
Why doesn’t it work? Bug or feature?
Edit
After reading didiers answer the problem is obvious. I missed that null can only be assigned to AnyRef types. For my problem I choose to make the tuple (n,n) and have a boolean flag whether the first entry is valid. Depending on the application Option might be a better solution.
Probably because your A parameter type is not guaranteed to be <: AnyRef. It should if you intend to pass null. If so, I would say feature
Edit. See Daniel’s comment below, the solution is >: Null, See AgileSteel answer too.