Rahul Chaudhary
02/17/2022, 9:29 PMWolfgang
02/18/2022, 1:42 AMTim Malseed
02/18/2022, 2:40 AMKiki Abdullah
02/18/2022, 9:11 AMfun <T> checkType(args: T): String {
return when(args) {
Int -> "Yes! it's Integer"
String -> "Yes! it's String"
Boolean -> "Yes! it's Boolean"
Double -> "Yes! it's Double"
listOf<Any>() -> "Yes! it's List"
mapOf<Any, Any>() -> "Yes! it's Map"
else -> "Can't identify"
}
}
But, when I call this function like checkType("I have 3 cats")
the output always display "Can't identify"
. What's wrong with my logic? Thanks in advanceSean Proctor
02/18/2022, 9:43 AMjava.util.prefs.Preferences
to Kotlin. Does anyone know of a decent wrapper to Preferences
or a Kotlin alternative? russhwolf/multiplatform-settings adds suspend/flow wrappers. I'm looking for an easy way to get/put lists, maps, and objects to preferences. Android has really polluted the Kotlin search space. 90% of the results are talking about SharedPreferences or DataStore.Karlo Lozovina
02/18/2022, 9:28 PM(1..10).forEach {
println(it)
return@forEach
}
print all of 10 numbers? what does even "return@forEach" mean here? It seems to work more like "continue", instead of "break"?Advitiay Anand
02/19/2022, 12:18 PMhfhbd
02/19/2022, 12:47 PMkt
val m: Map<String, Int> = mapOf("a" to 42, "b" to null).filterValues { it != null }
Any possibility to infer the not null type by the compiler? Workaround is a manual castAlexander Maryanovsky
02/19/2022, 1:12 PMfun foo(arg1: Int, arg2: Int = 42){ ... }
fun wrapper(arg1: Int, arg2: Int? = null){
if (arg2 == null)
foo(arg1)
else
foo(arg1, arg2)
}
Youssef Shoaib [MOD]
02/19/2022, 1:59 PMfun main() {
val test by MyCustomDelegate() = 5 //doesn't work
test = 5 //This is the current workaround
}
I don't want to change the implementation of MyCustomDelegate per se, I just want to call its setter in line.
Is that currently possible?Nat Strangerweather
02/19/2022, 6:02 PMAlderson Elliot
02/20/2022, 8:34 AMLokik Soni
02/20/2022, 4:23 PMKarlo Lozovina
02/21/2022, 12:33 AMMark
02/21/2022, 9:18 AMval lambda = if (myClickHandler == null) null else {
myClickHandler::onClick
}
I wish this was possible:
myClickHandler?::onClick
Jason5lee
02/21/2022, 3:55 PMgradle run
, readlnOrNull
immediately returns null without reading any input. How to fix it?harry.singh
02/21/2022, 5:22 PMmain
function private
in a kotlin file and it is still executable. How does JVM access the function if it is private
and make it executable?hfhbd
02/21/2022, 7:25 PMfun interface A {
fun foo(b: Int = 42) // Single abstract member cannot declare default values
}
TwoClocks
02/21/2022, 11:07 PMmaybeNull() ?: return
but this isn't maybeNull() ?: { return }
martmists
02/22/2022, 12:41 AMacoconut
02/22/2022, 8:51 AMMichael de Kaste
02/22/2022, 9:38 AMMap<KClass<out T>, SomeType<T>>
currently we are filtering from a list in multiple factories which is an O(factories * N) problem. Ideally I just want to request a class type from a map and get the correct implementationAhmed
02/22/2022, 12:33 PMclass Apartment ( val room1: String, val room2: String )
Alejandro Rios
02/22/2022, 12:49 PMMyFunction.invoke()
instead of MyFunction()
?smit01
02/22/2022, 6:20 PMrunBlocking{
println("init")
launch{
delay(200)
println("launch one")
}
println("mid")
launch{
delay(100)
println("launch two")
}
println("end")
}
init
mid
end
launch two
launch one
suspend fun cli(arg:String)=Runtime.getRuntime() .exec(arg).getInputStream().bufferedReader().readLines().forEach(::println)
runBlocking{
println("init")
launch{
cli("du -hs")
println("launch one")
}
println("mid")
launch{
cli("ls")
println("launch two")
}
println("end")
}
//optput
init
mid
end
11G .
launch one
AR
UB
storage
launch two
In this code why in second runBlocking i am not getting output like mentioned below where du -hs takes more time compare to ls command. In first runBlocking launch one has 200 delay so first second launch runs but in second runBlocking it doesn't why? Sorry for noob question or queries but I am new to coroutines and trying to learn.
init
mid
end
AR
UB
storage
launch two
11G
launch onecynth
02/22/2022, 8:10 PMAhmed
02/23/2022, 3:34 PMdata class Person (val gender: GenderEnum)
GenderEnum
enum class GenderEnum(val type: Sring) {
MALE("MALE")
FEMALE("FEMALE")
OTHER("OTHER")
}
and my api response is
"data": { gender: "male" }
Now, I am getting an error saying, Cannot construct instance of the Person class, problem: Parameter specified as non-null is null: gender
anyone has the problem with jackson before ?mcpiroman
02/23/2022, 5:30 PMStylianos Gakis
02/24/2022, 9:20 AMString.replace
function to replace some text. Specifically there was a place where this shows:
"""
"""
And I’d just like to replace it with:
"""
I was looking to use a triple quote String as I really like how I don’t need to escape stuff in there because it confuses me, but then I end up in this situation where I can’t really match a “”" inside it as it closes the string 😅 Is my only solution here to not use triple quotes since I can’t escape a “”" in there probably right? With a “\”\“\”\n \“\”\“” string instead?Michael de Kaste
02/24/2022, 9:52 AMfun main{
val scope = getScope()
when(scope){
// scope not smartcast and thus error
is DeeperScope.Impl1, is DeeperScope.Impl2 -> scope.someVar = "2"
}
}
interface Scope
sealed interface DeeperScope : Scope{
var someVar: String
data class Impl1(override var someVar: String) : DeeperScope
data class Impl2(override var someVar: String) : DeeperScope
}
fun getScope() : Scope = DeeperScope.Impl2("2")
Why can't scope be smartcast to DeeperScope in the when? Both implementations have their common parent as DeeperScope