Hildebrandt Tobias
09/10/2025, 7:56 AM2025-09-02T10:59:38+02:00 and at one point (envelope) I deserialize it as Instant with no problem.
At another point (payload) I want to do the same but it doesn't work. I looked at the imports but both import kotlinx.datetime.Instant .
But one does so from org.jetbrains.kotlinx:kotlinx-datetime and the other from org.jetbrains.kotlinx:kotlinx-datetime-jvm , with the latter not working.
The only dependency I have in both my common and jvmBackend modules is org.jetbrains.kotlinx:kotlinx-datetime so I guess it selects which one to use by itself.
What would be the best course of action to remedy this Problem?
Edit: Seems like I have to use Instant.parse() , before I had the json serializer do it, since most payloads are json and a select few are plain strings, but before I had no problems
just using the json parser for that and it allowed me to have a more generic approach for all messages.df
09/10/2025, 1:43 PMigor.wojda
09/10/2025, 4:48 PMJoshua Hansen
09/12/2025, 4:45 PMval at all somewhere other that its declaration site.
class Test {
private val test: String
init {
test = "Hello"
}
}Gasan
09/17/2025, 5:02 PMJoe
09/17/2025, 11:12 PM[WARNING] file:///home/jbarnett/workspace/tribe/leakycauldron/graphql/src/main/kotlin/com/trib3/graphql/execution/LeakyCauldronHooks.kt:50:30 This declaration overrides a deprecated member but is not marked as deprecated itself. Add the '@Deprecated' annotation or suppress the diagnostic.
... but gives no such warning in 2.2.10 (I mostly only care because -Werror). it looks like it is marked deprecated itself unless I'm missing something? I can, of course, override the non-deprecated methods instead but wanted to understand what's going on.min
09/18/2025, 7:31 AMthis.getChildAt(0) returns View! should it always be guarded with an if like this?
if (childCount > 0) {
getChildAt(0) as? AndroidComposeView
}
Why can’t I just do getChildAt(0) as? AndroidComposeView for an AndroidComposeView? that is null if the View! was null?min
09/20/2025, 12:26 PMAndreyVanDenHaag
09/23/2025, 6:07 AMSlackbot
09/29/2025, 1:51 PMSlackbot
09/29/2025, 1:51 PMYoussef Shoaib [MOD]
10/03/2025, 2:24 AMKlitos Kyriacou
10/03/2025, 11:00 AMfun foo(n: Int): Int {
require(n >= 1 && n <= 3)
return when (n) {
1 -> 10
2 -> 20
3 -> 30
}
}Joshua Hansen
10/03/2025, 10:52 PMimport com.whatever.DeprecatedClass <-- Deprecation warning persists
@Suppress("deprecation") <--- redundant suppression
fun test(value: DeprecatedClass) { ... }Colton Idle
10/09/2025, 8:07 PMSudarshan
10/15/2025, 2:19 PMVivek Modi
10/16/2025, 7:22 AMBernhard
10/16/2025, 12:29 PMinline fun <reified T : Any> createEvent(
endpointTarget: String,
id: String,
type: String,
payload: T,
) = Event(
endpointTarget = endpointTarget,
id = id,
type = type,
payload = payload,
typeInfo = typeInfo<T>()
)
class Event<out T : Any> private constructor(
val endpointTarget: String,
val id: String,
val type: String,
val payload: T,
val typeInfo: TypeInfo,
)Bernhard
10/22/2025, 2:13 PMJoshua Hansen
10/22/2025, 6:32 PMclass Foo {
var number: Int = 0
}
Is it possible to pass a reference to the number property to another class so that the other class can reassign it?CLOVIS
10/22/2025, 6:46 PMinline fun <reified T> foo(): T .
This function calls a function fun <T> impl(type: KType): T? .
I want the behavior that:
• If foo is called with a nullable type (e.g. foo<Int?>()), then nulls can be returned.
• If foo is called with a non-nullable type (e.g. foo<Int>()), if impl() returns null then it throws an NPE.
Is this possible?
Usually I would use overloads when I have two functions that only differ from the nullability of their parameters/receivers, but I don't think this is possible when they only differ by return type?Kirill Grouchnikov
10/22/2025, 7:12 PMInt , passing in the encoded ARGB channels, is there a more "pleasant" way of replacing
Hct.fromInt(0xFFFF0000u.toInt())
with something closer to how it is in Java
Hct.fromInt(0xFFFF0000)
the trailing u.toInt() is just noise when I read this call. The only thing I can think of is adding my own fun Hct.fromLong extension to make it read better in Kotlin.Jakob
10/24/2025, 2:48 PMdata class TimeRange(
val from: Instant,
val to: Instant?,
) {
fun isOpenEnded(): Boolean {
return this.to == null
}
}
Optimally, I'd like to be able to use this helper and have the compiler still correctly infer whether to is null or not.
If I now add a method to check if a TimeRange ends later than another, it might look like this (it's logically incorrect but nevermind that for the sake of the example)
fun endsLaterThan(other: Timerange): Boolean {
return this.isOpenEnded() || (!other.isOpenEnded() && (this.to > other.to))
}
However, this code does not work as-is, the compiler gives me trouble about nullability. To my human eyes and brain it's clear that the final statement (<http://this.to|this.to> > <http://other.to|other.to>) is only reachable if neither <http://this.to|this.to> or <http://other.to|other.to> is null, since that would short circuit the boolean operations. The compiler does not infer this, so I thought I might be able to help it along using contracts!
I have tried to add something like this, but it does not seem to work since I'm using implies to say something about a member of the receiver and not just the receiver itself?
fun isOpenEnded(): Boolean {
contract {
returns(true) implies this.to == null
returns(false) implies this.to != null
}
return this.to == null
}
If there's a way to make this work, I'd love to know! Links to reading material about contracts in general is also appreciated 👍Jobby
10/26/2025, 8:41 AMBoo,Boo,Boo,Boo,Boo,Boo
Foo,Foo,Foo,Foo,Foo,Foo
Goo,Goo,Goo,Goo,Goo,Goo
This is my code together with the output I get as comments.
import java.io.File
fun main() {
val chars: String = File(
"C:\\Work\\Kotlin\\test\\src\\main\\resources\\MyTest.txt"
).readText(Charsets.UTF_8)
val lines = chars.split("\n")
println("Number of Lines: ${lines.size}") // Number of Lines: 3
println(lines[0]) // Boo,Boo,Boo,Boo,Boo,Boo
println(lines[1]) // Foo,Foo,Foo,Foo,Foo,Foo
println(lines[2]) // Goo,Goo,Goo,Goo,Goo,Goo
val myList1 = lines[0].split(",")
val myList2 = lines[1].split(",")
val myList3 = lines[2].split(",")
println("myList1: $myList1") // ]
println("Number of Words: ${myList1.size}") // Number of Words: 6
println("myList2: $myList2") // ]
println("Number of Words: ${myList2.size}") // Number of Words: 6
println("myList3: $myList3") // myList3: [Goo, Goo, Goo, Goo, Goo, Goo]
println("Number of Words: ${myList3.size}") // Number of Words: 6
}
As you can see it only outputs myList3 correctly. myList1 and myList2 just output ']'. But if you look at the size, it seems like it processed my string correctly.
And the thing is, this depends on which line is the last in the txt file. It just outputs the last line the way I'd expect, but not the previous ones.
Why is that?
Is this a bug?
JDK: corretto-23.0.2
Ide: IntelliJ IDEA 2025.1.5.1 (Community Edition) - Build #IC-251.28293.39, built on September 2, 2025Shaun Wild
10/26/2025, 2:59 PMPihentagy
10/27/2025, 3:04 PMwhen is uncomplete?
https://pl.kotl.in/uwOMcC-FdCLOVIS
10/27/2025, 8:07 PMimport io.ktor.http.HttpStatusCode.*
@Serializable
private data class NotFound(val id: String)
val f = foo<NotFound>(NotFound)
| |
| HttpStatusCode.NotFound
data class NotFoundy
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.