Size: a a a

Kotlin Community

2019 October 28

VP

Vladimir Petrakovich in Kotlin Community
Andrey Antipov
О! Косяк выведения?
Так выводит:
sealed class Demo
object Foo : Demo()
fun <DEMO : Demo> DEMO.stringify(): String = when (this as Demo) {
   is Foo -> "Foo"
}

А так не выводит:
sealed class Demo
object Foo : Demo()
fun <DEMO : Demo> DEMO.stringify(): String = when (this) {
   is Foo -> "Foo"
}

При этом в первом случае IDEA логично говорит, что каст
this as Demo
не нужен, но без него компилятор тупит.
Может, это один из случаев, когда старый вывод типов не вывозит, раз идея говорит, что каст лишний?
источник

QH

Quantum Harmonizer in Kotlin Community
Amos 'D Great
val simpleAlert = AlertDialog.Builder(activity).create()
you should call all the setters before create()
источник

AM

Andrew Mikhaylov in Kotlin Community
Amos 'D Great
so please what do i do now ?
I'd visit Android docs and check if the code is written correctly. setMultiChoiceItems is the method of AlertDialog.Builder, but after calling create you are working with AlertDialog.
источник

AA

Andrey Antipov in Kotlin Community
Bogdan Panchenko
Пример можно, интересно
sealed class Ctx
class SimpleCtx : Ctx()
class ComplexCtx : Ctx()

typealias SimpleCtxF<T> = (SimpleCtx) -> T
typealias ComplexCtxF<T> = (ComplexCtx) -> T

fun <T> evalSimple(simpleCtxF: SimpleCtxF<T>): T = evalImpl(SimpleCtx(), simpleCtxF)

fun <T> evalComplex(complexCtxF: ComplexCtxF<T>): T = evalImpl(ComplexCtx(), complexCtxF)

private fun <CTX : Ctx, T> evalImpl(ctx: CTX, f: (CTX) -> T): T {
   /** some common actions */
   val isComplex = when (ctx as Ctx) {
       is SimpleCtx -> false
       is ComplexCtx -> true
   }
   return try {
       if (isComplex) {
           /** pre eval actions for complex context */
       }
       val t = f(ctx)
       if (isComplex) {
           /** on success actions for complex context */
       }
       t
   } catch (t: Throwable) {
       if (isComplex) {
           /** on failure actions for complex context */
       }
       throw t
   } finally {
       if (isComplex) {
           /** cleanup actions for complex context */
       }
   }
}
источник

AG

Amos 'D Great in Kotlin Community
Quantum Harmonizer
you should call all the setters before create()
Please how?
i dont seems to get it
kindly see my code pls
источник

DD

Damir Dobrev in Kotlin Community
u can simpleAlert.create()
источник

ПГ

Павло Гриник in Kotlin Community
почему его еще не отфутболили?
источник

QH

Quantum Harmonizer in Kotlin Community
Amos 'D Great
Please how?
i dont seems to get it
kindly see my code pls
источник

AM

Andrew Mikhaylov in Kotlin Community
I'm sorry. Two administrators mentioned that the question is off-topic here but gave you an actionable responses as to what you should change to make the code working. Further discussion seems unacceptable to me. Please find another place to talk on your code if you are not able to implement proposals yourself.
источник

AG

Amos 'D Great in Kotlin Community
this is very surprising to me ,
finally see what worked for me (i am very shocked with this still)

I changed

`simpleAlert.setMultiChoiceItems(paymentOptions, paymentOptionsChecked){ _, item, checked ->
                    paymentOptionsChecked[item] = checked
                }`

TO  


`AlertDialog.Builder(activity).setMultiChoiceItems(paymentOptions, paymentOptionsChecked){ _, item, checked ->
                    paymentOptionsChecked[item] = checked
                }`

😳😳
источник

AM

Andrew Mikhaylov in Kotlin Community
If you read the documentation, you'll be less shocked in the future.
источник

AM

Andrew Mikhaylov in Kotlin Community
Павло Гриник
почему его еще не отфутболили?
Fixed.
источник

QH

Quantum Harmonizer in Kotlin Community
что это, кому?
источник

AN

Alexander Nozik in Kotlin Community
Quantum Harmonizer
что это, кому?
троян же
источник

QH

Quantum Harmonizer in Kotlin Community
хмм, в каком смысле слова?)
источник

AN

Alexander Nozik in Kotlin Community
Quantum Harmonizer
хмм, в каком смысле слова?)
Вот и я тоже думаю
источник

DZ

Dmitrii Zubkov in Kotlin Community
Есть подозрение что паря просто промахнулся, и отправил сообщение не в тот чат
источник

AN

Alexander Nozik in Kotlin Community
Dmitrii Zubkov
Есть подозрение что паря просто промахнулся, и отправил сообщение не в тот чат
Ну тогда бы так и сказал 🤷‍♂️. Все промахиваются. У некоторых еще и дети до клавиатуры дорываются.
источник

MM

Maxim Motorniy in Kotlin Community
Коллеги, подскажите
fun observeLocation(): Flow<UserLocation> = callbackFlow { callback = { offer(it) } }
что я делаю не так?
Получаю эксепшн ClosedSendChannelException: Channel was closed
источник

СТ

Сергей Троян in Kotlin Community
да, промахнулся, сорри
источник