Animesh Sahu
11/12/2019, 4:10 PMSeri
11/12/2019, 4:14 PMapply()
has the inline
property, which allows it to copy the suspending context of its callerinline fun T.apply(block: T.() -> Unit): T
Animesh Sahu
11/12/2019, 4:16 PMkotlin
private suspend fun createUserSession(session: WebSocketServerSession, block: suspend UserSessionBuilder.() -> Unit): UserSession {
return UserSessionBuilder(session, server).apply(block).create()
}
here apply(block) give compiler error that type interference failedtseisel
11/12/2019, 4:20 PMapply
, but should instead write :
return UserSessionBuilder(session, server).apply { block() }.create()
Animesh Sahu
11/12/2019, 4:21 PMSeri
11/12/2019, 4:23 PM