Jason5lee
05/01/2021, 2:42 PMkotlin.io.AccessDeniedException
isn’t a alias of java.nio.AccessDeniedException
on JVM? Why creating such a new class that might confused the user that tries to catch this exception?thhh
05/02/2021, 2:12 PMtime
variable has a redundant initializer which is commented. When you uncomment and use that redundant initializer, program runs a lot faster.
Findings:
when using redundant initializer: 20000100000 in 28ms --> which is quite fast.
when removing redundant initalizer: 20000100000 in 103ms --> which is slow but is recommended by IntelliJ.
IntelliJ hint aside what causes the Kotlin program to run "slower" when NOT using redundant initlializer?thhh
05/02/2021, 4:35 PMthread
, the result is expected but when using launch
from Kotlin coroutine, the result is wrong and not expected.
Code: https://pl.kotl.in/cBD4j9XWb
In the code, as expected when using the thread
code in the for loop, the result prints 15000
but when using launch
for loop, the result prints 0 !? which is not expected.
Why is this happening and why launch
is giving wrong answer?Slackbot
05/04/2021, 6:54 PMSangmin Lee
05/05/2021, 7:48 AMvar metadata = field.getAnnotation(AnnotationA::class.java) ?: field.getAnnotation(AnnotationB::class.java)
if (metadata != null) {
someFunction(metadata) // which has two overrided functions with AnnotationA and AnnotationB
}
Compiler says “None of the following functions can be called with the arguments supplied.”
and it says metadata is casted to ‘Annotation!’
How can I set metadata AnnotationA or AnnotationB, and use my overrided function according to the type?Helio
05/06/2021, 8:02 AMCannot use 'T' as reified type parameter. Use a class instead.
means in this situation?
I’m trying to generalise the decodeFromString
and encodeFromString
but I’m confused why it doesn’t let me do that.
@ExperimentalLettuceCoroutinesApi
abstract class RedisDAO<T>(
private val keyPrefix: String,
private val ttl: Long, private val redisClient: BbcRedisClient
) {
open suspend fun getValueFromKey(key: String): T? {
val extractedValue = redisClient.getValueFromKey(key)
return extractedValue?.let { Json.decodeFromString<T>(it) }
}
open fun buildRedisKey(identifier: String): String {
return "$keyPrefix$identifier"
}
open suspend fun saveWithTTL(key: String, value: T) {
val encodedValue = Json.encodeToString<T>(value)
redisClient.storeKeyWithTTL(key, encodedValue, ttl)
}
}
Steven
05/06/2021, 4:45 PM@MicronautTest
?
@MicronautTest( environments = [ "Test"])
class RequestHandlerTestLocal: DescribeSpec ({
lateinit var applicationContext: ApplicationContext
describe("Lambda Tests") {
it("Creates correct Audit errors") {
// println( "hello-world" + applicationContext.environment )
//TODO
}
}
})
result is an ignored test.Helio
05/12/2021, 2:45 AMDaniele B
05/12/2021, 7:24 AMList<String>
like this:
val myList = listOf("paramA","paramB","paramC")
I can enforce an API like this?
fun myFunc (paramA: String, paramB: String, paramC: String)
basically a function, which has those strings as names for String arguments?Daniele B
05/12/2021, 12:37 PMPepijn de Vos
05/13/2021, 10:38 AMRuckus
05/13/2021, 9:11 PMmod
tells you how far into a chunk you are, and floorDiv
tells you which chunk you are in. Is getting the start of the given chunk as simple as floorDiv * chunkSize
? Is it more complicated than that? Is my mental model fundamentally wrong?Andrew Ebling
05/14/2021, 10:21 AMenum class
implementing an interface in a TreeMap
such a way that I can set/get set them without throwing a ClassCastException
?
So far I have:
interface MyEnumInterface {}
enum class MyEnumClass: MyEnumInterface { ... }
var myTreeMap: TreeMap<MyEnumInterface, (() -> (Unit))> = TreeMap()
however when I call this method, passing an instance of `MyEnumClass`:
fun add(howToExecute: () -> (Unit), myEnum: MyEnumInterface) {
myTreeMap[myEnum] = howToExecute // ClassCastException here
}
... I get a ClassCastException
.
Why does this happen? Why doesn’t it happen when the instance is passed to the add() method?
What’s the most appropriate resolution please?Daniele B
05/17/2021, 7:44 PMe.g. val list = listOf(3,9,1,6,7)
if I add a new 9, it would removes the old one:
list.add(9)
println(list) // listOf(3,1,6,7,9)
Daniele B
05/18/2021, 9:52 AMval a = mapOf(2 to "W", 3 to "V", 1 to "T")
desired result:
val list = listOf("T","W","V")
I was reading you can do that using sortedMap
, but it doesn’t come out on the IDE.Soe
05/18/2021, 10:24 AMevkaky
05/20/2021, 10:10 AMval map = mutableMapOf("key1" to 1)
map["key1"] += 2
Why Is it not possible to use increment in such a way?Justin Yue
05/24/2021, 11:48 PMreadLine()
from the kotlin.io package or to use `Scanner(System.in
)` from the java.io package? I think my personal preference is going the Java route because I feel that returning String?
from readLine()
is something I don't want to deal with. But maybe I'm not using Kotlin's null safety as much as I should be?oday
05/25/2021, 2:19 PMid
exists in the list of ordersthhh
05/25/2021, 4:50 PMStub!
means? In kotlin code, I tried to see the Declaration of Exception. In there, I found a Stub!
string. What does it mean. Image: https://i.imgur.com/6WX2nfQ.png▾
maarten ha
05/25/2021, 8:44 PMCannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option
Adding support for Java 8 language features could solve this issue.
The app is an kmm project. In both the shared build as the android build file is the compileOptions with javaversion 1.8 set but still getting the error
I don’t know gradle that well and if I need to place this somewhere else let me knowColton Idle
05/26/2021, 5:43 PMmario
05/26/2021, 7:50 PMwydra91
05/27/2021, 7:36 AMwydra91
05/27/2021, 8:10 AMDennis Tel
05/27/2021, 2:02 PMRuckus
05/27/2021, 5:14 PMfun main(args: Array<String>)
over fun main(vararg args: String)
?Zan Skamljic
05/28/2021, 8:34 PMblockList.all { name.contains(it, true) }
?Andrea Giuliano
06/02/2021, 8:35 AMmyMutableSet.removeAll(collection)
myMutableSet.take(x)
now I’d like not to use take since the set can contain millions of items and I’d like not to copy all in a new set..any suggestions?
There is no constraints on the “which” X items to take..random is finephisch
06/02/2021, 1:18 PMmutableListOf
inside of commonMain
. I can use it in every other directory (commonTest
, nativeMain
and nativeTest
). I have reinstalled the IDE, the Kotlin plugin, disabled all other plugins, tried the EAP and created multiple new projects to test this, and it is always the same issue. Here is a video showing that this doesn't work in `commonMain`:phisch
06/02/2021, 1:18 PMmutableListOf
inside of commonMain
. I can use it in every other directory (commonTest
, nativeMain
and nativeTest
). I have reinstalled the IDE, the Kotlin plugin, disabled all other plugins, tried the EAP and created multiple new projects to test this, and it is always the same issue. Here is a video showing that this doesn't work in `commonMain`:mutableListOf
will not be available in commonMain
when copying this test class to `commonMain`:Timo Gruen
06/02/2021, 2:03 PMsrc/org/example/app
should be the “main” package of your application / code.
Btw. tests are not in the src
module, instead one typically has a test
module with the same package structure like your src
:
test/org/example/app
*main
which might collide with some internal logic of intellij.phisch
06/02/2021, 2:06 PMmutableListOf
in commonMain
and then when i restart it, it doesn't find it again. Its completely random, idk.Timo Gruen
06/02/2021, 2:08 PMphisch
06/02/2021, 2:09 PM