Rasheed
12/13/2022, 1:16 PMdave08
12/13/2022, 4:09 PMordinal
field of an enum start by 2 instead of 0? I'm using a third party ksp parser that uses the ordinal for something that I need to skip the first three numbers for...dave08
12/13/2022, 4:20 PMenum class Foo { NA1, NA2, NA3, Bar, Baz }
where NAx shouldn't be used... 😛Paul Griffith
12/13/2022, 10:01 PMClass<T?>
? E.G. I need a class literal for a Double?
, so I was going to use Double::class.javaObjectType
, but I have to “unsafely” cast that to make the compiler happy. Simplified example of what I’m doing, sort of: https://pl.kotl.in/OQI60v_tVTodor Grudev
12/14/2022, 8:57 AMdata class Coordinate(val x: Int, val y: Int) {
val bottom: Coordinate = copy(y = y + 1)
}
I am trying to do the following thing, but I get StackOverflowError
is it because I am trying to refer something that I am defining?Sulaimon Abdullahi Oluwaseun
12/14/2022, 5:43 PMNico Wickersheim
12/15/2022, 8:32 AMmartmists
12/15/2022, 1:55 PMfun Pair<Int, Int>.sumIsEven() = (first xor second) and 1 == 0
fun Pair<Int, Int>.sumIsEvenAlt() = (first + second) % 2 == 0
I would assume the former to be faster as it doesn't require summing and dividing and just does bitwise comparisons, but I'm getting the following results:
=== Case 1 ===
Average: 42ns
Max: 546_802ns
Total: 42_349_933ns
=== Case 2 ===
Average: 36ns
Max: 52_984ns
Total: 36_907_022ns
What's the reason for this difference?xun su
12/16/2022, 8:34 AMVariable 'xxx' must be initialized
? look the code below:
class CompanyResource {
companion object {
val allNames: Map<String, String> =
mapOf(
someone.first to someone.second // error: Variable 'someone' must be initialized
)
val someone =
Pair<String, String>(
"peter" , "blunt"
)
}
}
Rob Elliot
12/16/2022, 10:04 AMval x by delegate
?
I could stick it in a cache in the Delegate class, but wondering if there's a simpler way... I suppose I could wrap it in a lazy, but I'd rather it was eagerly evaluated. I'm really only using it for syntax sugar to reduce boilerplate.Kirill Grouchnikov
12/16/2022, 4:58 PMval tree = IntervalTree<Int>()
tree.add(IntegerInterval(1, 4, Interval.Bounded.CLOSED))
tree.add(IntegerInterval(6, 8, Interval.Bounded.CLOSED))
// This ends up with three intervals [0,7], [1,4], [6,8]
tree.add(IntegerInterval(0, 7, Interval.Bounded.CLOSED))
What I’m looking for is for the data structure to end up holding the “unified” interval of [0,8] after this third operation.
And the same for deletion. If I have a single [0,8] interval and I remove [2,4], it should now have two intervals - [0,2] and [4,8].trc
12/16/2022, 9:41 PMnkiesel
12/17/2022, 4:56 AMDamien O'Hara
12/17/2022, 12:29 PMLastExceed
12/17/2022, 1:01 PMhttps://i.imgur.com/moQvnG1.png▾
Colton Idle
12/17/2022, 5:09 PMarrayListOf
and `listOf`exist? Both seem to be of Type ArrayList?Jan
12/18/2022, 8:34 PMKProperty
In Kotlin/JS?Klitos Kyriacou
12/19/2022, 11:11 AMinc()
and get()
are supposed to return, so how can it check if the values are correct?Roach
12/19/2022, 2:52 PM@JvmStatic
when converting java file to kotlin?
this result occurs compile errorNat Strangerweather
12/19/2022, 6:16 PMitems(state.newsFeedItems) {println(listOf(it.feedTitle).distinct())}
Gasan
12/20/2022, 1:31 PMclass SpySleeper: Sleeper {
lateinit var sleepDuration: Duration
override fun sleep(d: Duration) {
sleepDuration = d
}
}
interface Sleeper {
fun sleep(duration: Duration)
}
Gasan
12/20/2022, 1:57 PMkotlin-stdlib
sources jar?Lukasz Kalnik
12/20/2022, 4:26 PMBiMap
(bidirectional hashmap)?masteramyx
12/20/2022, 8:17 PMmartmists
12/21/2022, 2:21 AMopen class A {
open fun C.extMethod() { ... }
}
class B : A() {
override fun C.extMethod() {
// Somehow call A's implementation
// Then do extra behavior
}
}
super.extMethod(this)
doesn't seem to resolve unfortunatelyPHondogo
12/21/2022, 7:30 AMinterface IFace {
fun test()
fun test2()
// etc...
}
class A : IFace {
override test() {}
override test2() {}
// etc...
}
class B : IFace {
private val a = A() // Is it possible to specify that B must delegate all IFace functions to a without passing a in constructor?
}
Otis Goodman
12/22/2022, 3:10 AMjava.lang.IllegalStateException: Symbol with IrPropertySymbolImpl is unbound
at org.jetbrains.kotlin.ir.symbols.impl.IrBindableSymbolBase.getOwner(IrPrivateSymbolBase.kt:59)
at org.jetbrains.kotlinx.serialization.compiler.backend.ir.IrBuilderExtension$DefaultImpls.searchForProperty(GeneratorHelpers.kt:342)
I can send a link to my code on Github if needed.dave08
12/22/2022, 11:44 AMdata class Foo(val bar: String, val baz: Int)
and I want to only have a list with a unique bar
with the max baz
. Say [0] -> bar = "one", baz = 1 and [1] -> bar = "one", baz = 2, the resulting list should be in the same order and only contain [2]... how do I do this in the most concise and efficient way?Kai Yuan
12/23/2022, 1:13 PMdata class
and set.contains(e)
If I didn't understand it wrong, set.contains(e)
checks elementInSet.equals(e)
. Also, data class creates equals()
method for the properties in the primary constructor.
Now, I'm wondering why I get this output:
data class Foo(var v: Int)
fun test() {
val mySet = mutableSetOf(Foo(1))
mySet.forEach {
it.v += 1
}
println("mySet contains: $mySet")
val f = Foo(2)
println("$f in Set? ${f in mySet}")
println("equals? ${f == mySet.toList().first()}")
}
Output:
mySet contains: [Foo(v=2)]
Foo(v=2) in Set? false
equals? true
Why f in mySet
returns false?coroutinedispatcher
12/23/2022, 2:06 PM