Wxffel
03/16/2023, 5:11 PMMeika
03/16/2023, 6:26 PMConcurrentModificationException
when iterating (and modify) a mutable list. detail in thread 🧵to-elixir
03/17/2023, 1:19 AMSam Garfinkel
03/17/2023, 1:21 AMMaria Krishtal
03/17/2023, 11:45 AMTarun
03/17/2023, 1:29 PMRuckus
03/17/2023, 4:46 PMsealed class Bounds<in T : Comparable<T>> {
abstract operator fun contains(value: T): Boolean
}
And I want
object Unbounded : Bounds<Any?> {
override fun contains(value: Any?) = true
}
However, I cannot as Any?
violates the type bound. Is there a way to specify the type to make this work?J
03/18/2023, 2:48 AMManasseh
03/18/2023, 8:53 AMjean
03/18/2023, 3:56 PMprivate fun <T> MutableList<T>.addAll(vararg element: T) = element.forEach { add(it) }
It’s only possible to pass a collection, an array, an iterable or a sequence as far as I can see. Which is not idealistic when I want to do something like this
val list = MutableList<Int>()
when {
someReason() -> list.addAll(1, 2, 3)
someOtherReason() -> list.addAll(4, 5, 6)
}
y
03/18/2023, 7:30 PMArrayDeque.removeFirst()
an O(1)
operation?Mark
03/19/2023, 3:07 AMfun <T> Foo<T>.getValue(): T
val foo: Foo<Boolean> = ...
println("no problem: " + foo.getValue())
val fooAnyValue: Any = foo.getValue()
println("also no problem: " + fooAnyValue)
val fooValue = foo.getValue()
println("class cast exception (fooValue is not a Boolean): " + fooValue)
Pawan
03/19/2023, 7:48 AMcallsInPlace
Kotlin contracts and found an error in it, how can I correct it by contributing? I am new to open source and would love to contribute to Kotlin. Help would be appreciated.Lukasz Kalnik
03/20/2023, 9:27 AM@CartesianTest.Values
annotation with an array literal, but I get an error (Kotlin 1.8.10):vbsteven
03/20/2023, 6:01 PMpublic inline fun Boolean.asGBoolean(): Int = if (this) 1 else 0
Jimmy Zhou
03/20/2023, 9:15 PMwebServerExchange
object).
My initial attempt is:
1. pass the context from reactor to coroutine using context capture, and later i can retrieve the context without needing the webServerExchange
object
2. define an customized annotation such as WithReactiveContext
3. add this annotation to my controller class so that all my suspending function will be wrapped inside an different coroutine context (instead of the default one)
My questions are:
1. do you guys think this is a legit approach given my context
2. if this approach sounds okay, how do I trigger the annotation method using reflection so that all the suspending functions in annotated class is wrapped within a different coroutine context
3. if this approach does not make sense whats an alternative solutionVitali Plagov
03/21/2023, 11:39 AMopen class BaseTest {
lateinit var browser: Browser
lateinit var page: Page
@BeforeEach
fun setUp() {
browser = Playwright.create().chromium().launch()
page = browser.newPage()
}
}
But I don't like to use a mutable lateinit var
modifiers. How can I turn these two into immutable variables? Using lazy
? But then the variable will be initialized only once.Lukasz Kalnik
03/21/2023, 3:27 PMprivate val
inside a companion object through reflection?Ink
03/22/2023, 3:41 PM<?xml version="1.0" standalone="yes"?><svg version="1.1" width="383" height="383">
How I can get width
and height
value using Regex?Sam Stone
03/22/2023, 4:43 PMclass ObservableList<T>: MutableList<T> by Collections.synchronizedList(ArrayList()) {
But when I override a function, it gives an error: Abstract member cannot be accessed directly
override fun add(element: T): Boolean {
val add = super.add(element)
mObserver.postValue(this)
return add
}
y
03/23/2023, 4:14 PMclass Foo(val s: String)
interface MyInterface {
fun Foo.bar(): String
}
object MyImpl : MyInterface {
override fun Foo.bar(): String = this.s
}
then given val myImpl = MyImpl
and an instance of Foo
, how/when can I call `MyImpl`'s implementation of bar()
?y
03/23/2023, 5:23 PMinterface MyInterface<R> {
fun doIt(): R
}
object MyImpl : MyInterface<String> {
override fun doIt(): String = "hello"
}
object MyOtherImpl : MyInterface<Int> {
override fun doIt(): Int = 5
}
which works fine.
now say I've got fun <R> foo(impl: MyInterface<R>): R = impl.doIt()
is it possible to add a default value to impl
?
fun <R> foo(impl: MyInterface<R> = MyImpl) = impl.doIt()
doesn't compile.
the best I could come up with is to also add an overload of `foo`:
fun foo() = foo(MyImpl)
.Daniel
03/23/2023, 6:39 PMKai Devrim
03/23/2023, 11:16 PMMuhammad Junaid
03/24/2023, 9:05 AMDavid Kubecka
03/24/2023, 9:55 AMval (xs, nonXs) = list.partition { it is X }
// xs is of type List<X>
Fray Contreras
03/24/2023, 2:31 PMTech
03/24/2023, 6:56 PMval list1 = listOf("hello", "world")
val list2 = listOf(*list1, "test")
I mainly just need to spread list1 into list2 so the type is List<String> on list2krzysztof
03/24/2023, 10:26 PMJosh Yoo
03/25/2023, 2:19 AMJosh Yoo
03/25/2023, 2:19 AMasdf asdf
03/25/2023, 2:59 AM