Wesley Acheson
12/13/2019, 10:00 AMParthiv Mistri
12/13/2019, 10:38 AMArrayList<Model>
in which Model
has an Int
value between 1 to 10
. I need to sort them in Descending order.
Can anyone help me to do this?
Thanksmirror-kt
12/13/2019, 12:44 PMoverride fun fromJson(reader: JsonReader): Volumes? {
val volumes = mutableListOf<Volume>()
while (reader.hasNext()) {
val path = reader.nextName()
reader.skipValue()
volumes.add(Volume(path))
}
return Volumes(volumes)
}
override fun toJson(writer: JsonWriter, value: Volumes?) {
if(value == null) return
writer.beginObject()
for(volume in value.volumes) {
writer.name(volume.path)
writer.beginObject()
writer.endObject()
}
writer.endObject()
}
Wesley Acheson
12/13/2019, 2:29 PM/**
* Adds a new item to a new list, returning the new list.
* @param item the item to add to the list
* @return A new list with `item` added to the end.
*/
private fun <T> List<T>.add(item: T): List<T> {
val copy = this.toMutableList()
copy.add(item)
return copy
}
which as far as I can see creates a new array list by copying the data.Nikky
12/13/2019, 3:01 PMhttps://i.imgur.com/QaHuNPf.png▾
jojo.lichtenberger
12/13/2019, 5:17 PMsnowe
12/13/2019, 5:33 PMfun a(n: Int)=if (n/3-2 <= 0) 0 else n/3-2 + a(n/3-2)
results in this error
Error:(107, 46) Kotlin: Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly
Jared
12/14/2019, 3:33 AMtipsy
12/14/2019, 12:06 PMv0ldem0rt
12/14/2019, 3:25 PMKirill Shepelev
12/14/2019, 5:00 PMrobstoll
12/14/2019, 6:45 PMfun foo(i: Int): String = ...
fun bar(i: Int): String by foo // does not work, is there another syntax?
Tim McCormack
12/15/2019, 1:03 AMVinicius Carvalho
12/15/2019, 1:11 AMsteenooo
12/15/2019, 10:04 AMAshutosh Panda
12/15/2019, 12:25 PMval list= listOf<Int>(5,3,2,4,2)
println(list)
clear(list)
println(list)
Ashutosh Panda
12/15/2019, 12:27 PMlist=emptyList()
is there any other waythymecypher
12/16/2019, 2:33 AMShan
12/16/2019, 4:29 AMsteenooo
12/16/2019, 8:49 AMJoffrey
12/16/2019, 10:02 AMkotlin-test
I'd be happy to learn about them.Ashutosh Panda
12/16/2019, 11:46 AMSimon Kågedal Reimer
12/16/2019, 11:57 AMsomeObject.javaClass.kotlin.declaredMemberProperties
– are there any guarantees about the order of the properties? It seems to be alphabetical in my test, but I don’t see any explicit documentation – can I trust that? Is there any way to get them ordered as in source code?marstran
12/16/2019, 4:52 PMfun main() {
var curr = listOf(1).asSequence()
curr = curr.map { curr.sum() }
println(curr.sum())
}
While this works fine:
fun main() {
var curr = listOf(1).asSequence()
val done = curr.map { curr.sum() }
println(done.sum())
}
Do anyone know why this happens? It also works if I remove the sum
inside the map
. The weird thing is that it makes a difference whether I assign the result to a new variable or not.ghedeon
12/16/2019, 5:33 PMif
but fails otherwise.
Type mismatch error:
sealed class Foo
object Valid : Foo()
object Empty : Foo()
fun doSomething1(): Result<Foo> {
return Result.failure<Valid>(Exception()).recover { if (true) Empty else Valid }
}
Works fine:
fun doSomething2(): Result<Foo> {
return Result.failure<Valid>(Exception()).recover { Empty }
}
jef
12/16/2019, 8:06 PMKy Leggiero
12/16/2019, 9:14 PMpaco
12/16/2019, 11:51 PMA problem occurred evaluating project ':kotlin.web.demo.backend'.
> Could not resolve all files for configuration ':versions:1.3.60:kotlinJS'.
> Could not resolve org:Kotlin_KotlinRelease_1360_Aggregate:1.3.60-release-155.
Required by:
project :versions:1.3.60
> Could not resolve org:Kotlin_KotlinRelease_1360_Aggregate:1.3.60-release-155.
> Could not get resource '<https://buildserver.labs.intellij.net/guestAuth/repository/download/Kotlin_KotlinRelease_1360_Aggregate/1.3.60-release-155/teamcity-ivy.xml>'.
> Could not GET '<https://buildserver.labs.intellij.net/guestAuth/repository/download/Kotlin_KotlinRelease_1360_Aggregate/1.3.60-release-155/teamcity-ivy.xml>'. Received status code 400 from server: Bad Request
I have realized the url of the teamcity server has changed from <http://teamcity.jetbrains.com>
to <https://buildserver.labs.intellij.net>
and the last one requires a personal certificate. Anyone know how to fix this error?alexsimo
12/17/2019, 10:33 AM"{\"asdasdasdasd\": \"asd\"}"
ShootingStar
12/17/2019, 1:01 PMThe bitwise operations and, or, and xor are familiar to most developers. The only difference between them and their logical counterparts is that they do not short-circuit. - Kotlin Cookbook
Does anyone can explain what does the short-circuit means ?ShootingStar
12/17/2019, 1:01 PMThe bitwise operations and, or, and xor are familiar to most developers. The only difference between them and their logical counterparts is that they do not short-circuit. - Kotlin Cookbook
Does anyone can explain what does the short-circuit means ?Jaymin.Kim
12/18/2019, 9:44 AMfun foo() = false
fun boo() = { print("boo!"); true }
print("a = ")
foo() && boo()
print("\nb = ")
foo() and boo()
result:
a =
b = boo!
&&
is short-circuit.
this means, foo()
is false
, so boo()
don't need to call. so skipped.
and
is not short-circuit.
even foo()
is false
, boo()
will call.
This only works for Boolean