https://kotlinlang.org logo
#android
Title
# android
j

jw

12/23/2017, 7:50 PM
Retrofit
j

James Coggan

12/23/2017, 8:13 PM
Thanks @jw, it was more about how the public APIs where written, ie retrofit in java uses a builder that you provider adapters, would you recommend the same structure in kotlin with all the null’s around?
or just work with lateinit/defaults for all of it?
to be more specific, lets say my lib builds an object that depends on another that you build if not started, would this be a good approach?
Copy code
fun build() = {
            if (!::okHttpClient.isInitialized) {
                okHttpClient = defaultOkHttpClient(loggingInterceptor)
            }
...
f

fuad

12/23/2017, 8:41 PM
@James Coggan @antonioleiva has some really nice examples of how using Retrofit in Kotlin can be much simpler than in Java
one sec I dig up some links
j

James Coggan

12/23/2017, 8:42 PM
this more a builder question than retrofit 😉
f

fuad

12/23/2017, 8:43 PM
ok, well anyway here’s a write up from him https://antonioleiva.com/retrofit-android-kotlin/
j

jw

12/23/2017, 8:43 PM
To your specific example, I'd use nullable not lateinit
If I rewrote Retrofit in Kotlin I wouldn't change much
j

James Coggan

12/23/2017, 8:44 PM
thanks!
appreciate it
i did feel
isInitialized
is a bit of a smell
@fuad ty anyway
👍 1
6 Views