Ankur Verma
08/16/2022, 5:46 PMsreich
08/16/2022, 6:15 PMval opList = operations.computeIfAbsent(
basePath
) { key: String? -> ArrayList() }
mitch
08/16/2022, 6:53 PM?.
making variables look nullable causing type mismatches. Are there any best practices on how to do these upgrades incrementally?
As an aside, is there a more appropriate channel for this post? Feels like we need a #versions or #upgrading
Thanksnkiesel
08/17/2022, 1:52 AMbuild/generated-src/antlr/main
and have a package com.example.antlr
first line (i.e. there is a mismatch between the directory path and the package path, but AFAIK the Koltin compiler does not care about that). I tried to fix the compile error using
val antlrGeneratedFilesDirectory = file("${buildDir}/generated-src/antlr/main")
idea {
module {
generatedSourceDirs.add(antlrGeneratedFilesDirectory)
sourceDirs.add(antlrGeneratedFilesDirectory)
}
}
but that did not help either. Anyone has an idea what I could try to fix this?
BTW: I can navigate in IntelliJ to the generated sources from the import statement, so IntelliJ does somehow find the files.Jerry Yion
08/17/2022, 1:04 PMAlex
08/17/2022, 3:38 PMval aMap= mapOf("one" to 1,"two" to 2)
fun main() {
aMap.mapValues { (z,y)-> "$"+z;"$"+y }.forEach{z->println(z)}
}
maarten ha
08/17/2022, 4:13 PMSiddhartha Juluru
08/17/2022, 5:16 PMfun <P : Enum<P>> BaseConstraints<out Any, P>.validEnum(
init: Unit.() -> Unit
) {
this.rules.add(ValidEnum())
}
and it is only valid when I do validEnum<Status> { }
(where Status is my enum) but not when I do validEnum<Status?> { }
. I can make it accept the latter by doing
fun <P : Enum<P>> BaseConstraints<out Any, P?>.validEnum(
init: Unit.() -> Unit
) {
this.rules.add(ValidEnum())
}
but then I am unable to do validEnum<Status> { }
Ben Edwards
08/17/2022, 5:56 PMval purchasedTickets: Int = 10
val totalTickets: Int = 100
percentagePurchased = (purchasedTickets/ totalTickets) * 100
This is obviously going to truncate the numbers inside the brackets so the answer will be wrong but what is the correct way to handle this?Ben Edwards
08/17/2022, 6:42 PMBen Edwards
08/17/2022, 8:05 PMBen Edwards
08/18/2022, 5:13 PM*val* reader = FileReader("test.txt")
reader.*use* {
reader.read()
}
Which can be replaced by
FileReader("test.txt").use { reader -> read("something") }
Which I am confused by, what is "something" referring to?Lawrence
08/18/2022, 5:26 PMmcpiroman
08/20/2022, 9:41 AMfun foo(vararg words: String) {
val a: Array<String> = words
}
Why do I get:
Type mismatch.
Required: Array<String>
Found: Array<out String>
Gregory Risch
08/21/2022, 11:09 AMDan MacNeil
08/21/2022, 5:27 PMfun main() {
val num = 5.0
val num0 = String.format(Locale.ENGLISH, "%02.0f", num)
val num2 = String.format(Locale.ENGLISH, "%02.2f", num)
println("num0 = $num0, num2 = $num2")
}
This prints: num0 = 05, num2 = 5.00Jérémy CROS
08/22/2022, 2:34 PMprivate var aVariableToKeepTrackOfSomeData : SomeClass? = null
fun AnotherClass.myExtentionFunction() {
// do stuff here with the variable
}
Is it scoped to the application?
Does that look like a bad idea? 😅Slackbot
08/23/2022, 4:43 AMColton Idle
08/23/2022, 7:35 AMstate.myList[index] = state.myList[index].copy(isFollowing = !state.myList[index].isFollowing!!)
A lot of ceremony just to flip the value of isFollowing
Ben Edwards
08/23/2022, 12:34 PMenum class LootType {
POTION, RING, ARMOR
}
class Loot(val name: String, val type: LootType, val value: Double) {
}
Main.kt
fun main(args: Array<String>) {
...
val redPotion = Loot("Red Potion", lootType.POTION, 7.5)
}
I am getting unresolved reference LootType. The Loot.tk file has no errors.jkbbwr
08/23/2022, 1:48 PMjkbbwr
08/23/2022, 1:48 PMenum class Example(val str: String) {
header("123")
}
jkbbwr
08/23/2022, 1:48 PMjkbbwr
08/23/2022, 1:49 PMheader
is not a keyword listed anywhereSam
08/23/2022, 1:53 PMjkbbwr
08/23/2022, 1:53 PMjkbbwr
08/23/2022, 1:54 PMjkbbwr
08/23/2022, 1:54 PMBen Edwards
08/23/2022, 2:30 PMYusuf.I
08/23/2022, 2:44 PM