xii
06/21/2022, 6:59 PMawaitAll()
with different variables of different types for it to not be casted as Any?Vaios Tsitsonis
06/22/2022, 8:45 AMbuildList
, buildMap
, etc. due to Unresolved reference
. In my gradle file I have added a stdlib dependency. So why does this happen? Does it need some extra configuration?cheeze2000
06/22/2022, 10:51 AMStephan Schroeder
06/22/2022, 12:12 PM<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
but what do I do if I have a multi-module project? ${project.basedir}/src/main/kotlin
lacks the module in it's path, doesn't it?sreich
06/22/2022, 4:31 PMKotlin version that is used for building with Maven (1.7.0) differs from the one bundled into the IDE plugin (1.6.10)
sreich
06/22/2022, 9:16 PMUbed
06/23/2022, 8:05 AMElizeu Silva dos Santos
06/23/2022, 11:43 AMFile.forEachLine
is a good choice for that?Guilherme D. Fernandes
06/23/2022, 5:48 PMcheeze2000
06/24/2022, 1:55 AMb in a..c
has the same performance as a <= b && b <= c
?Rodrigo Silva
06/24/2022, 3:48 AMrunCatching
block
like:
runCatching {
when (some_condition) {
1 > failure
else -> todo
}
Joffrey
06/24/2022, 1:23 PMis
check on Kotlin/JVM, in the sense that it doesn't fail with NoClassDefFoundError
if the class is not on the classpath?
I would like to do something with an object if it's of a given type, with the smart cast, but I don't want it to fail if running on lower JDK that doesn't have that class, I just want the condition to be false, and the code to move on without trying to load the class.cheeze2000
06/24/2022, 1:35 PMsreich
06/24/2022, 1:45 PMAlfred Lopez
06/24/2022, 5:35 PMimport kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.Default
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
class TestMutex {
val mutex = Mutex()
suspend fun createJobs() {
val job1 = CoroutineScope(Default).launch {
println("Job1")
acquireMutex("Job1")
}
val job2 = CoroutineScope(Default).launch {
println("Job2")
acquireMutex("Job2")
}
val job3 = CoroutineScope(Default).launch {
println("Job3")
acquireMutex("Job3")
}
joinAll(job1, job2, job3)
println("Delaying for a bit...")
delay(1000)
println("Done")
}
suspend fun createJobs2() {
CoroutineScope(Default).launch {
repeat(3) {
CoroutineScope(Default).launch {
println("Job$it")
acquireMutex("Job$it")
}
}
}.join()
println("Delaying for a bit...")
delay(1000)
println("Done")
}
suspend fun acquireMutex(id : String) {
if (!mutex.isLocked) {
mutex.withLock {
println("Got here...$id")
}
}
else {
println("I was directed to here...$id")
}
}
}
suspend fun main() {
val testClass = TestMutex()
println("First run...")
testClass.createJobs()
println("Second run...")
testClass.createJobs2()
}
elect
06/24/2022, 6:13 PMjava.lang.Boolean(true)
, which returns a boxed Boolean) won't be seen as different keys, that is they would be overwritten
how can I solve it?kotlinforandroid
06/25/2022, 3:20 PMclass FormField {
var hasError: Boolean by mutableStateOf(false)
var errorMessage: String? by mutableStateOf(null)
// errorMessage != null iff. hasError == true
}
I tried contracts but one cannot reference variables that are not part of the contract method. I can't reason about this@FormField.errorMessage
inside the implies boolean expression.stvn
06/26/2022, 10:31 AMKlitos Kyriacou
06/26/2022, 12:03 PM(list1 + list2).firstOrNull { it.matches(something) }
but without eagerly iterating the lists and creating a new list from them?
In other words, exactly like Guava's FluentIterable.concat(list1, list2)
but more Kotlin-idiomatic?Rachel Carandang
06/26/2022, 3:19 PMfun degreesToDirection(degrees: Float?): Direction {
var smallestDistance: Float = Float.POSITIVE_INFINITY
lateinit var direction: Direction
degreesMapping.entries.forEach {
if (abs(it.value - (degrees ?: 0f)) < smallestDistance) {
direction = it.key
smallestDistance = (degrees ?: 0f) - it.value
}
}
return direction
}
Andrew
06/26/2022, 4:45 PMJavier
06/26/2022, 10:59 PMDslMarker
markers and picking the nested one?
If I have two function with the same name, the outermost is used
kotlin {
android() // from kotlin
multiplatform {
common()
android() // from kotlin, should be from multiplatform
jvm()
}
}
Lawrence
06/26/2022, 11:25 PM@Serializable
@Resource("/end_point")
class EndPoint(val query: String? = "")
client().get(EndPoint())
This results in: <http://base_url/end_point?query=>
but I just want it to be <http://base_url/end_point?query>
Hassaan
06/28/2022, 1:51 PMniqo01
06/28/2022, 10:41 PM[error] Compliance level '1.4' is incompatible with target level '11'. A compliance level '11' or better is required.
It 's a simple gradle kotlin("jvm") project with:
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
I have no idea what Compliance level isRodrigo Silva
06/29/2022, 1:45 PMabstract class SomeClass {
abstract fun someFunction(someParameter: String) : List<String?>
}
suspend inline fun <reified T : SomeClass> otherFunction(): Return<T> {
val someAtt = T::someFunction("abc")
}
error:
left-hand side of callable referece cannot be a type parameter
v79
06/29/2022, 8:04 PMe: D:\Development\Experiments\Pellet\server\src\main\kotlin\dev\pellet\server\PelletServerClient.kt: (8, 17): Unresolved reference: UnixDomainSocketAddress
IntelliJ can see the import (no red squiggly lines). In Project Structure, I've chosen SDK `openjdk-18 java version "18.0.1"`(and I've also tried the cornetto variant of JDK18). The language level is set to 17 in InteilliJ and in the build.gradle.kts
file. In IntelliJ's External Libraries view I can drill down to <http://java.base.java.net|java.base.java.net>
and see the UnixDomainSocketAddress
class (it was introduced in Java 16).
But neither IntelliJ nor Gradle can find the class to compile it! (I've even dug into the JDK source folder, and it definitely exists!). Please, any ideas?Rohan Maity
06/30/2022, 7:03 AModay
06/30/2022, 9:34 AMKieran Wallbanks
06/30/2022, 9:52 AM