dany giguere
10/15/2022, 8:07 PMSlackbot
10/16/2022, 4:56 AMErik
10/16/2022, 2:54 PMfun foo
in this runnable example in a way that doesn't provide a value for the first parameter with a default value? The types of the first two parameters happen to be compatible, which is unfortunate (even though they're not the same!)maxmello
10/17/2022, 1:10 PMfun <T: Any?> a(b: (value: T) -> Unit) {
b(null)
}
why does this not work? Why does it say T is non-nullable, even though it uses Any?
? Can I make this work without changing the lambda param to value: T?
?Settingdust
10/18/2022, 6:58 AMb
in a(c[0]!!(), b)
will error with type mismatch. Expected CapturedType(out B*>)
but B<*>
. How to pass the b
as param?
https://pl.kotl.in/VVNMv8Zso Edited: add comment
// KSerializer in my actual env
open class A<T>
// An external class from lib
class B<T>
// My serializer
class C : A<B<Int>>()
// A map to take correct serializer by arg
val c: Map<Int, () -> A<out B<*>>> = mapOf(0 to { C() })
// CompositeEncoder#encodeSerializableElement in my actual env
fun <U, T : A<U>> a(a: T, b: U) {
}
// KSerializer#serialize(encoder: Encoder, value: B<*>) in my actual env
fun b(b: B<*>) {
a(c[0]!!(), b)
}
Error
Type mismatch.
Required:
CapturedType(out B*>)
Found:
B<*>
y
10/18/2022, 8:39 AMResult
in Kotlin, and is it idiomatic to use it? do failible functions in Kotlin generally return error types on failure, throw, or just return `null`/silently exit?y
10/18/2022, 11:30 AMvar maybe_null = if (condition) { method_chain_that_may_return_null() } else { null }
Loney Chou
10/18/2022, 2:41 PMabstract
can be inner
, but sealed
, data
not?reactormonk
10/18/2022, 3:56 PMretry
or similar for `try`/`catch`?Luis Lopez Gonzalez
10/19/2022, 6:46 AMy
10/19/2022, 7:11 AMmy_uint += 1
the type of 1 is not Int
?andylamax
10/19/2022, 9:23 AMinline constructors
are prohibited but there is an exception for the Array
class implementation?Rohit Lagu
10/19/2022, 8:18 PMNorbi
10/20/2022, 8:02 AMAyfri
10/20/2022, 12:42 PMif
Viktor Sirotin
10/20/2022, 8:24 PMMartin Kolesar
10/21/2022, 1:21 PMTech
10/21/2022, 7:21 PMkotlin("jvm") version "1.7.20"
Trying to use data objects but run into this error The feature "data objects" is only available since language version 1.8
, thanks in advance.Joshua Hansen
10/21/2022, 10:58 PMfoo: String
and bar: List<String>
. What's a clever way to return true if foo
starts with (or I guess contains
works too) at least one string in bar
?hfhbd
10/21/2022, 11:34 PMinterface F
class B<T>(t: T) : F by t where T : F
David Hu
10/22/2022, 4:01 AM"foo" > "bar"
magically works in Kotlin REPL and returns a boolean instead of throwing an error or exception?
how is it even possible to "compare" strings this way when the same code in Java does not work at all?!v79
10/22/2022, 7:03 AM?.let { }
block, no less. The value from the repository is hypothetically null, but I thought the let block would have handled that.Loney Chou
10/22/2022, 2:36 PMMikael Ståldal
10/24/2022, 7:50 AMpackage mypackage
fun main(args: Array<String>) {
// ...
}
Usually used as program entrypoint in JVM.
However, when I try to call it from another Kotlin module:
import mypackage.main
class MyClass {
fun myMethod() {
main(arrayOf("foo", "bar"))
}
}
I get this strange error:
Kotlin: Overload resolution ambiguity:
public fun main(args: Array<String>): Unit defined in mypackage
public fun main(args: Array<String>): Unit defined in mypackage
Yogeshvu
10/24/2022, 3:18 PMNat Strangerweather
10/25/2022, 2:27 PMif (option.id == 0) {
for (o in listOfOptions) {
when (o.id) {
1 -> enabled = false
2 -> enabled = false
}
}
}
But all my 3 buttons are disabled when I do this... 🤔Michael de Kaste
10/25/2022, 4:16 PMsealed interface Foo
sealed interface Bar
sealed interface Thing {
object ONE : Thing, Foo
object TWO : Thing, Bar
}
fun main(){
val thing: Thing = Thing.ONE
if(thing is Foo && thing is Bar){
// This can´t happen
}
}
Ink
10/26/2022, 8:44 AMname: tom, weight: 50, age: 21
How I can get value name
, weight
, age
?Nat Strangerweather
10/26/2022, 4:57 PMfunction1 ()
and function2 ()
into suspend functions, and set them up like this:
val scope = rememberCoroutineScope()
ElevatedButton(
onClick = {
scope.launch {
function1 ()
function2 ()
}
},
The problem is that I need for function1 to be completed before function2 can start. So if I put a 1 second delay between the two, my app works as expected, but if I don't it seems function2 does not wait for function1 to complete before it starts. Is there a way to get f1 to finish before f2 starts without adding a delay in between the two?Joseph S
10/26/2022, 7:23 PMJoseph S
10/26/2022, 7:23 PM