Maybe I am missing something fundamental here, but I was reviewing some things in my code, and halfway through I noticed that my code is compiling where I expect it to not. So here is the method signature:
def checkUiFieldValue[T](fieldName:String, uiValue:T, expectedValue:T):Unit ={...}
Here is the place where it is used:
checkUiFieldValue("State", stateInListView(ar.name), ar.state)
The return type stateInListView
is the class ARState
, and the type ar.state
is String
. So the question is, why does it compile and does not tell me that the types do not match? I caught myself thinking that I expect the compiler to verify that uiValue
they expectedValue
are of the same type T
, but probably my guess is wrong.
Or T
does the type parameter in the method definition actually mean that both arguments will be passed in Any
in my case? If so, how should I properly restrict both arguments to the same type at compile time?
source
share