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 stateInListViewis the class ARState, and the type ar.stateis 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 uiValuethey expectedValueare of the same type T, but probably my guess is wrong.
Or Tdoes the type parameter in the method definition actually mean that both arguments will be passed in Anyin my case? If so, how should I properly restrict both arguments to the same type at compile time?
source
share