althaf
10/11/2021, 8:57 AMclass CurrentServerTimestamp {
private val lock: ReentrantLock = ReentrantLock()
private var timestampInMillis: Long
get() = lock.withLock { timestampInMillis }
set(value) {
lock.withLock { timestampInMillis = value }
}
init {
timestampInMillis = CURRENT_SERVER_TIME_NOT_SET
}
companion object {
private val instance = CurrentServerTimestamp()
fun isValidTimeStamp(): Boolean {
return instance.timestampInMillis != CURRENT_SERVER_TIME_NOT_SET
}
fun get(): Long = instance.timestampInMillis
fun set(currentServerTimestamp: Long) {
instance.timestampInMillis = currentServerTimestamp
}
}
}
set(value) {
lock.withLock { timestampInMillis = value }
}
I think this is causing the dead lock, is there any way to over come this and still i get the intended behavior ?Colm Murphy
10/11/2021, 11:14 AMshl
or shr
infix functions. Is this intentional or not?Carl Bateman
10/11/2021, 2:57 PMMuhammad Usama
10/11/2021, 5:22 PMblue
10/11/2021, 10:30 PMval record = (repository.findById(id) ?: (<http://log.info|log.info>("log message here") return))
Brad Harris
10/11/2021, 11:27 PMJérémy CROS
10/12/2021, 3:31 PMdata class Foo(val a:Int, val b = 0)
val bar = Foo(a = 3, if(param) b = 5 /*else keep the default param */)
Is there an alternative other than val bar = if(param) Foo(...) else Foo(...)
missguru
10/12/2021, 3:43 PMShabinder Singh
10/12/2021, 6:08 PMKarlo Lozovina
10/12/2021, 8:46 PMassociateWith
returns?ankushg
10/13/2021, 12:50 AMManuel Dossinger
10/13/2021, 7:54 PMfun foo(a: Type1, b: Type2, c: Type3): Type4
val result: Type4? = foo(myA?, myB?, myC?) // is null if any of the parameters is null
Mihai Voicescu
10/14/2021, 10:11 AMdave08
10/14/2021, 11:36 AMsealed interface Foo
object Bar : Foo
object Baz : Foo
fun <T : Foo> getFooObjects(): List<T> = TODO("How do I get this list?")
egek
10/14/2021, 1:45 PMPeterpaul Klein Haneveld
10/15/2021, 8:03 AMAyfri
10/15/2021, 2:04 PMMihai Voicescu
10/15/2021, 3:59 PMJakub Aniola
10/17/2021, 12:37 PMStylianos Gakis
10/17/2021, 4:22 PMvalue class
?
Like I see the benefits of it, but if I am creating a new data class with 1 parameter anyway, why would I not just make it a value class? Any gotchas? Couldn’t find anything in the KEEP regarding this.Vitali Plagov
10/18/2021, 8:24 AMdata class ProfileItem(val id: String, val item: Item)
data class Item (val code: String)
When I get a List<ProfileItem>
from the 3rd service (can’t control it), the item
field for some elements in the list might be null
. And when I do
val eligibleCodes = service.gerProfileItems().filter { it.item.code in approvedCodes }
it fails with NPE, so I had to do filter { it.item != null }
once I got the list. And IntelliJ complains about this filtering saying that this condition is always true.
Is it an issue with the IntelliJ IDEA’s inspection? Or I should do this operation differently?conner
10/18/2021, 7:00 PMinstanceof
checks -- so naturally various stack overflow answers mentioned "code smell", and i'm wondering if there's truth to that 🙂
sealed class Node
data class Leaf(x: Int): Node()
data class Tree(left: Node, right: Node?): Node()
Alejo
10/19/2021, 1:24 PMMihai Voicescu
10/19/2021, 3:04 PMimport kotlinx.serialization.*
import kotlinx.serialization.json.Json
import kotlin.test.Test
sealed interface iFoo {
@Serializable
@SerialName("a")
class A() : iFoo//Foo(),
}
class EventTest {
@Test
fun testKotlinLang() {
// // this works
// val json = Json { serializersModule = SerializersModule {
// polymorphic(iFoo::class) {
// subclass(iFoo.A::class, iFoo.A.serializer())
// } } }
val json = Json
val a = iFoo.A() as iFoo
val s = json.encodeToString(a)
val a1: iFoo = json.decodeFromString(s)
}
}
Itamar F. Lima
10/19/2021, 6:10 PMKarlo Lozovina
10/19/2021, 8:59 PMsomeCollection.take(42).forEach { /* ... */ }
is there a way to access the collection inside the forEach that the forEach is iterating over?Michael Langford
10/19/2021, 9:30 PMblue
10/19/2021, 11:51 PMstudent as Student
from the below code? Don’t I have to explicitly assign the cast result to a variable to access the score
property?
abstract class Person(val name: String)
class Student(val score: Int, name: String) : Person(name)
class Teacher(name: String) : Person(name)
fun someFun(student: Person) {
// student as Student
println(student.score)
}
nilTheDev
10/21/2021, 8:03 AMBert Heyman
10/21/2021, 9:36 AMBert Heyman
10/21/2021, 9:36 AMDamian Zawadzki
10/21/2021, 9:38 AMBert Heyman
10/21/2021, 9:39 AM