MR3Y
10/05/2023, 7:40 PMexpect fun <T : HttpClientEngineConfig> getEngineFactory(): HttpClientEngineFactory<T>
where HttpClientEngineFactory
is defined as:
public interface HttpClientEngineFactory<out T : HttpClientEngineConfig>
and on Jvm actual implementation is:
actual fun <T : HttpClientEngineConfig> getEngineFactory(): HttpClientEngineFactory<T> {
return OkHttp
}
where OkHttp
is defined as:
public object OkHttp : HttpClientEngineFactory<OkHttpConfig>
and for OkHttpConfig
:
public class OkHttpConfig : HttpClientEngineConfig
the problem is that the actual implementation doesn't compile because of type mismatch, required: HttpClientEngineFactory<T>
found: OkHttp
return OkHttp as HttpClientEngineFactory<T>
but I want to understand what is the problem here and if there is a better solution than the Unchecked castephemient
10/05/2023, 7:50 PMOkHttp
isn't a HttpClientEngineFactory<T>
, it's a HttpClientEngineFactory<OkHttpConfig>
, and it's possible the caller may use !(T : OkHttpConfig)
MR3Y
10/05/2023, 8:03 PMHttpClientEngineFactory<T>
?ephemient
10/05/2023, 8:04 PMfun getEngineFactory(): HttpClientEngineFactory<*>
since the caller doesn't get to choose the typeMR3Y
10/05/2023, 8:09 PM