y
10/29/2025, 2:25 PMfun <T> foo1(vararg elements: Iterable<T>) = /* ... */
I also have fun foo2(vararg elements: List<Bar>)
what exactly happens when I call foo1(*elements) from within foo2?
what does the spread operator do here? is this zero cost?Bernhard
10/30/2025, 9:40 AMgenerateSequence { Elem(it.hasNextPart())}.takeUntil {it.hasNext}
is there a better way to do that? and in that case, would you prefer an Iterator instead?Gasan
10/31/2025, 10:44 AMval? Kotlin does not have a concept of a "pointer to a const", therefore I can change the referenced value, unless it is immutable. I mean, val parameter variable does not amount to much unless the referenced value is immutable.ursus
11/01/2025, 12:50 AMy
11/03/2025, 9:44 AMCannot invoke "java.util.Map.get(Object)" because the return value of "A.getMethods()" is null
which we seem to get, but only sometimes.
we have this: (A, B, C are all concrete classes, renamed to anonymize)
abstract class A(/* ... */) : Lots, Of, Things {
abstract override val methods: Map<B?, C>
abstract override val someMethod: C?
/* ... */
override fun getMethods(): List<C> = methods.values + listOfNotNull(someMethod)
}
what could be the issue here?
is it an order of initialization thing?
is it related to the choice of the name getMethods? (since kotlin desugars getters to that name, no?)CLOVIS
11/03/2025, 5:12 PMJack Boyce
11/04/2025, 7:59 AMBernhard
11/04/2025, 11:58 AMhfhbd
11/05/2025, 11:14 AMnull in Map<String, String>.get(null): mapOf<String, String>("f" to "f").get(null as String?)Edgar Avuzi
11/08/2025, 5:52 AMelect
11/09/2025, 10:55 AMimport org.gradle.api.Project
import java.io.ByteArrayOutputStream
context(_: Project)
operator fun String.invoke(vararg args: String): String {
val output = ByteArrayOutputStream()
providers.exec { // error, `providers` unresolved
commandLine("arduino-cli", "version")
standardOutput = output
}
return output.toString()
}Rob Elliot
11/09/2025, 11:09 AMfun nullableReturn(): String? = TODO()
val timer: Timer = TODO()
try {
timer.recordCallable {
nullableReturn()
}
} finally {
timer.close()
}
> Argument type mismatch: actual type is 'CallableString?', but 'Callable<uninferred T! (of fun T : Any recordCallable)>!' was expected.Natalia Mishina
11/10/2025, 12:42 PMJérémy CROS
11/10/2025, 3:59 PMclass Provider {
private val listener by lazy {
object: 3rdPartyListener {
// Bunch of callbacks
// The one I actually care about
override fun onError() {
// Spam errors when in errors, do nothing otherwise
}
}
}
}
I've read about callbackFlow but I can't quite make it work.
For the use case of a callback that spam error / do nothing, AI is suggesting using a debounce but I don't know, that seems weird...
Any help / suggestions appreciated! 🙏Lukasz Kalnik
11/13/2025, 2:17 PMJoshua Hansen
11/17/2025, 7:40 PMAssigned value is never read on aNumber += 1 even with the suppressions. I personally consider this warning wrong but I'm sure people could argue about it. Is there anyway to suppress it?
Also, why did the `Wrapped into a reference object to be modified when captured in a closure." statement go away?
class Foo(val lambda: () -> Unit)
@Suppress("UNUSED_VARIABLE", "UNUSED")
fun test() {
var aNumber = 0 // "Wrapped into a reference object..." doesn't show anymore
val newFoo = Foo {
val test = 1 + aNumber // Do something with current value
aNumber += 1 // Change value to be used next time Foo.lambda() is called
}
// do something with newFoo here to use later like add it to a list, etc.
}Pihentagy
11/19/2025, 7:39 AMJoshua Hansen
11/19/2025, 7:25 PMinterface Test<T: Number> {
val clazz: KClass<T> // Keep reference to the class so we can find the right one later
fun foo(item: T)
}
// Int object:
object A : Test<Int> {
override val clazz = Int::class
override fun foo(item: Int) {
// do something
}
}
// Double object
object B : Test<Double> {
override val clazz = Double::class
override fun foo(item: Double) {
// do something
}
}
fun test() {
// Working with a list of these objects
val objs: List<Test<out Number>> = listOf(A, B)
val myInt = 1
// I'm certain find returns A, but due to forced out projection I get an error.
val properObj = objs.find {
it.clazz == myInt::class
}
properObj?.foo(myInt) // Receiver type 'Test<out Number>' contains out projection which prohibits the use of 'fun foo(item: T): Unit'.
}MrNiamh
11/20/2025, 3:47 PMa compile fine, but b is a compilation error? I wouldn't expect a to compile but it does, but i'm also surprised it's not consistent between the two.
data class ContactId(val value: UUID)
fun main(){
val contactId = ContactId(UUID.randomUUID())
val uuid = UUID.randomUUID()
val a = contactId == uuid
val b = contactId.toString() == uuid
}Slackbot
11/24/2025, 5:59 PMStephan Schröder
11/24/2025, 8:48 PMname , at least the Kotlin version doesn't.Edgar Avuzi
11/29/2025, 3:10 AMPihentagy
11/30/2025, 11:59 AMGasan
12/01/2025, 10:09 AMclass MyClass(val myProperty: Boolean|MyType) . The type of myProperty is a union of Boolean and MyType types. That is, myProperty value can be one of those types.Slackbot
12/01/2025, 4:38 PMSlackbot
12/02/2025, 1:49 PMPihentagy
12/03/2025, 2:44 PMokarm
12/05/2025, 5:08 PMe: java.lang.IllegalStateException: Unexpected member: <DANGLING MODIFIER: Top level declaration expected>
at org.jetbrains.kotlin.fir.backend.Fir2IrConverter.processMemberDeclaration(Fir2IrConverter.kt:551)
...
when compiling a hefty chunk of generated code. How can I find which source file(s) is problematic? No Gradle logging option up to and including --debug makes the compiler print any more information.ursus
12/08/2025, 1:06 AMkqr
12/08/2025, 7:32 AM