Slackbot
03/16/2020, 4:01 PMPawel
03/16/2020, 6:19 PMvar a: Int? = null
try {
a = doSthToGetA()
useA(a)
} catch(ex: AnyExc) {
doSthWithA(a)
}
xii
03/16/2020, 8:28 PMMax
03/16/2020, 8:29 PMprintln()
during a gradle task? (especially a continuous one)Mike Conley
03/17/2020, 6:09 AMfoo
actually doesKashif
03/17/2020, 6:10 AMPrateek
03/17/2020, 8:24 AMDuplicate class kotlin.reflect.KClasses found in modules jetified-kotlin-reflect-1.0.7.jar (org.jetbrains.kotlin:kotlin-reflect:1.0.7) and jetified-kotlin-stdlib-1.3.70.jar (org.jetbrains.kotlin:kotlin-stdlib:1.3.70)
Can anybody help me figure out this error? I am unable to run tests because of itPandaH.
03/17/2020, 10:16 AMInt?
) or generics are involved. In the latter cases numbers are boxed." What does it mean by boxed?Paul N
03/17/2020, 12:29 PMTsvetan Ovedenski
03/17/2020, 1:37 PMdata class Item (val name: String)
sealed class Permission <T> {
object Create : Permission<Unit>()
object Edit : Permission<Item>()
}
fun <T> verify(permission: Permission<T>, item: T): Boolean = when (permission) {
is Create -> true
is Edit -> item.name == "editable" // Unresolved reference: name
}
For some reason I expected that when it's known that T
is Item
(as it is in Edit
), then item
would be properly casted, but I realise that maybe I expected too much. Any idea on how to connect the two (permission
and item
)?bod
03/17/2020, 4:01 PMval isStateXyz = xx.state in setOf(FOO, BAR, FOOBAR)
Is this idiomatic? Also, I think it may be a bit bad performance...
So I was thinking of creating this:
inline fun Any?.equalsAny(vararg objects: Any?): Boolean = objects.any { this == it }
and use it like this val isStateXyz = xx.equalsAny(FOO, BAR, FOOBAR)
Is it a good idea or should I just keep using in
? Thoughts?Steve
03/17/2020, 4:52 PMcedric
03/17/2020, 8:01 PMthe short story is that it exists for compatibility with code that came before generics were a thing.@Mike Conley That's not quite true, erasure was mostly picked for its superiority over reification in many different areas. It would have been possible to have reified generics in Java without breaking any backward compatibility, it just wouldn't have been wise 🙂
Anastasia Finogenova
03/17/2020, 10:06 PMhooliooo
03/17/2020, 10:39 PMChristian Sousa
03/18/2020, 1:00 PMconst myArray = ['1', '2', '3']
let myObj = {
default = '0'
}
myArray.forEach(elem => {
myObj = {
...myObj,
[`newProperty-${elem}`] = elem
}
})
Is there any way to do something like that in Kotlin?
Basically, I just need a way to create an object with a variable amount of propertiesCosmin Victor Celea
03/18/2020, 2:07 PMLastExceed
03/18/2020, 2:16 PMsuspend fun main() {
val items = MarketAPI.getItems()
for (index in items.indices) {
println(items[index])
}
items.forEach {
println(it)
}
}
the return type of MarketAPI.getItems()
is List<Item>
where Item
is a simple data class storing 3 Strings.
the first loop works fine, the second one gives me this error: https://hastebin.com/ewuvakikuy
how is this possible? how can the way i iterate through the items affect the serialization AFTER it happens?
I cant even figure out where exactly it happens. the stacktrace says line 12 in main.kt, however that file only has 11 lines. I set a breakpoint and stepped through, the crash occurs as soon as i reach the second loop. but due to coroutine shenanigans the stacktrace isnt very helpfulGilberto Diaz
03/18/2020, 3:03 PMAjinkya Saswade
03/18/2020, 3:03 PMAnimesh Sahu
03/18/2020, 3:19 PMChristian Sousa
03/18/2020, 3:42 PMChills
03/19/2020, 8:44 AMilya_ryabchuk
03/19/2020, 11:24 AMChristian Sousa
03/19/2020, 11:39 AMfun myFunction(list: List<String>): List<String> {
return list.map {
return it
}
}
It complains about the return type being a string instead of a List<String>Chills
03/19/2020, 12:39 PMstanislav.erokhin
Chills
03/19/2020, 3:16 PMNothing
cant be reified type? whyelect
03/19/2020, 4:05 PM() -> Unit
or a Runnable
(on pure kotlin)?angarron
03/19/2020, 4:34 PM@Synchronized
fun notify(updates: Set<UpdateSource>) {
Log.d("findme", "notify START: $updates")
observers.forEach { observer ->
/* stuff */
}
Log.d("findme", "notify END")
}
@Synchronized
private fun disconnect(observer: Observer) {
Log.d("findme", "disconnect START")
observers.remove(observer)
Log.d("findme", "disconnect END")
}
and I see these logs:
2020-03-19 09:25:16.545 21962-22072/com.discord.debug D/findme: notify START: [com.discord.stores.StoreUser@c7528b5, com.discord.stores.StoreUser$Companion$UsersUpdate$1@91882e5]
2020-03-19 09:25:16.548 21962-22072/com.discord.debug D/findme: disconnect START
2020-03-19 09:25:16.548 21962-22072/com.discord.debug D/findme: disconnect END
Can anyone explain how it's possible that "notify END" never prints? if that forEach
was hanging, I would expect a hung thread, but we are able to enter the disconnect
method -- which means that I feel like I'm misunderstanding something about @Synchronized