Is there a way to write this line of code in a bet...
# codereview
a
Is there a way to write this line of code in a better way?
val httpLoggingInterceptor = HttpLoggingInterceptor().level = HttpLoggingInterceptor.Level.BODY
a
Copy code
val httpLoggingInterceptor = HttpLoggingInterceptor().apply {
    level = HttpLoggingInterceptor.Level.BODY
}
a
The word of
apply
is telling to carry out another action after declare the variable?
a
yes, you are `apply`ing additional code to the instance
a
Thanks.
b
You can also statically import
HttpLoggingInterceptor.Level.BODY
so it becomes
val httpLoggingInterceptor = HttpLoggingInterceptor().apply { level = BODY }
c
What's wrong with the way it is written in the question?
b
Nothing. Just longer.