mickeelm
12/12/2020, 11:54 AMprivate fun <String> HashMap<String, String>.myExt(key: String, incomingValue: String) {
this[key] = incomingValue
}
But not this
private fun <String> HashMap<String, String>.myExt(key: String, incomingValue: String) {
this[key] = "something else"
}
The latter gives me (in IntelliJ):
Type mismatch.
Required: String#1 (type parameter of myExt)
Found: kotlin.StringJoris PZ
12/12/2020, 11:58 AMthis[key] = "something else" as String fixes the compiler error?Joris PZ
12/12/2020, 12:03 PMString#1? Seems like a bugmickeelm
12/12/2020, 12:03 PMJoris PZ
12/12/2020, 12:04 PMfun HashMap<String, String>.myExt(key: String, incomingValue: String) {
this[key] = "something else"
}Joris PZ
12/12/2020, 12:04 PM<String> makes no sense hereJoris PZ
12/12/2020, 12:05 PMString as a generic type parameter instead of kotlin.String?mickeelm
12/12/2020, 12:05 PMJoris PZ
12/12/2020, 12:05 PMmickeelm
12/12/2020, 12:05 PMString vs kotlin.String I don't know reallyMilan Hruban
12/12/2020, 1:27 PMString in the original function is just a name you have given to the generic parameter, it has nothing to do with kotlin.String. You could replace it with Abcd (or more often used T) and the function would work exactly samemickeelm
12/12/2020, 1:31 PMJoris PZ
12/12/2020, 2:15 PMMilan Hruban
12/12/2020, 2:31 PMmickeelm
12/12/2020, 2:32 PMnanodeath
12/13/2020, 5:44 PMMatteo Mirk
12/14/2020, 11:31 AMMessage<REQUEST, RESPONSE>
or in Assertj:
interface Assert<SELF extends Assert<SELF, ACTUAL>, ACTUAL> ...