Daniele B
09/23/2021, 4:52 PMByteBuffer
in Kotlin MultiPlatform.
Is there anything similar I can use?Endre Deak
09/23/2021, 8:38 PM// this delegation works
interface A { fun foo() }
interface B { fun bar() }
class AImpl() : A { override fun foo() = println("default foo") }
class BImpl(private val a: AImpl) : B, A by a { override fun bar() = println("bar") }
// ==============
// how could I do a delegation for an inherited interface?
interface A { fun foo() }
interface B : A { fun bar() }
class AImpl() : A { override fun foo() = println("default foo") }
// no idea how to delegate
class BImpl(private val a: AImpl) : B by a { override fun bar() = println("bar") } // ?
suhas
09/24/2021, 2:35 AMlist.sortedWith(compareBy ({
when(it.state) {
A -> -1
B -> 0
C -> 1
}
}))
This returns a list were all the elements with state A come first, followed by B and then followed by C. I am just not able to wrap head around this though. I understand how comparable works by overriding compareTo function and comparing two objects that the function gets. But not this. Can someone please explain this to me :)Simon Lin
09/24/2021, 4:23 AMlist: ["a", "b", "c", "d", "e", "f", "g"]
give specify position: 3
result: ["a", "b", "c"]
Danish Ansari
09/24/2021, 7:27 AMString
(just a scenario), so does that have any impact on performance?
Just want to understand how exactly extension functions work and if there's any cost (or disadvantage) in using it that I should be aware of.Daniel Svensson
09/24/2021, 8:08 AMantoniomarin
09/24/2021, 10:59 AMdata class Test<T>(
val key: String,
val additionalData: T
)
inline fun <reified T> Test<*>.checkSafeCast(): Test<T>? {
return if (this.additionalData is T) {
this as Test<T> // Unchecked cast
} else {
null
}
}
Ayden
09/24/2021, 2:21 PMintervals = [[1,3],[2,6],[8,10],[15,18]]
Arrays.sort(intervals, compareBy { it[1] })
Hi guys, may i know how can i sort it in descending order based on the first index?Brian Donovan
09/24/2021, 3:42 PMknthmn
09/25/2021, 4:57 AMfun main() = runBlocking {
// ... launch some stuffs
// wait for ctrl-C, how?
cleanup()
cancel()
}
Kiprop Victor
09/25/2021, 10:36 AMelect
09/25/2021, 6:07 PM+
and -
operators with implicit receiver?
branchFilter {
+"refs/heads/my-feature"
}
elect
09/26/2021, 9:46 AMHamza Ahmad
09/27/2021, 12:09 PMJilles Soeters
09/27/2021, 10:40 PMVitali Plagov
09/28/2021, 10:15 AMobject
with constants defined as const val
. I want to get a list of all constants available in this object. Is there a convenient way to get them? I tried with reflection: MyObjectWithConstant::class.declaredMemberProperties
elect
09/28/2021, 11:51 AMYousef
09/28/2021, 3:26 PMdata class Category(
val id: UUID,
var title: String,
var slug: String,
var subCategories: List<Category>
)
Vitali Plagov
09/28/2021, 5:42 PMrunCatching
-equivalent of the try {} finally {}
code in Java?
Is it what the recover{}
function does?Dipendra Singh
09/28/2021, 8:49 PMfun getStreetNameByStreetId(id: String): String {
val query = Query()
query.fields().include("name")
query.addCriteria(Criteria.where("_id").`is`(id))
var streetName = ""
mongoTemplate.executeQuery(
query, STREET_COLLECTION
) { document: Document ->
streetName = document.getValue("name").toString()
}
return streetName
}
Manuel Dossinger
09/29/2021, 7:08 AMaddOrRemove(element, boolean)
function for sets (or collections) in the stdlib?
Something that does if (boolean) set.add(element) else set.remove(element)
elect
09/29/2021, 8:30 AM@DslMarker
annotation class a method, this gets displayed as yellow?
Is this because we want to explicitly show to the user that this is a DSL method?Javier
09/29/2021, 8:14 PMkotlin {
explicitApi = ExplicitApiMode.Disabled
}
Error:
Unknown value for parameter -Xexplicit-api: 'disabled'. Value should be one of {disable, strict, warning}
The enum class:
enum class ExplicitApiMode(private val cliOption: String) {
Strict("strict"),
Warning("warning"),
Disabled("disabled"); // this should be renamed to disable and/or in another place have to check for disabled instead of disable
fun toCompilerArg() = "-Xexplicit-api=$cliOption"
}
William Reed
09/30/2021, 1:37 PMval classes: List<KClass<*>> = listOf(
Person::class,
Teacher::class,
)
And this produces an error
val classes: List<KClass<Any>> = listOf(
Person::class,
Teacher::class,
)
(the difference being *
vs Any
)
I want to store any kclass, and don’t know the types. I thought *
meant they all have the same type but i don’t know what it isScott Whitman
09/30/2021, 1:47 PMclass CompassHeading(degrees: Double) {
private var _degrees by Delegates.notNull<Double>()
var degrees: Double
get() = _degrees
set(value) {
var d = value % 360.0
if (d < 0.0) d += 360
_degrees = d
}
init {
this.degrees = degrees
}
}
elect
09/30/2021, 3:32 PMinterface Action {
// interface DSL Builder
operator fun<T> invoke(block: T.() -> Unit)
}
Because I cant seem to properly override in the implementation..Byron Woodfork
09/30/2021, 3:48 PMJan
09/30/2021, 7:45 PMJason5lee
10/01/2021, 2:11 AMcdpjenkins
10/01/2021, 10:52 AMfun <T> doNothing(param: T): Unit = Unit
or an equivalent lambda and I’m wondering if there is a standard function that I can do in order to not have to write this function myself.cdpjenkins
10/01/2021, 10:52 AMfun <T> doNothing(param: T): Unit = Unit
or an equivalent lambda and I’m wondering if there is a standard function that I can do in order to not have to write this function myself.Joffrey
10/01/2021, 11:05 AM{ Unit }
. If you need to implement a method (like an override), you can just use Unit
as your implementation bodycdpjenkins
10/01/2021, 11:29 AMephemient
10/01/2021, 5:56 PM{ }
should work, although explicitly stating Unit
is clearer