kotlin

Kotlin JaCoCo, no coverage -> IllegalClassFormatException … Please supply original non-instrumented classes

假如想象 提交于 2021-02-07 12:19:05
问题 kotlin verion: 1.3.61 Android Gradle Plugin: 3.5.3 JaCoCo Version: 0.8.4.201905082037 (default android gradle version) project: https://github.com/goldy1992/Mp3Player/tree/feature/issue-112/migrate-to-kotlin I have a multi module gradle project with: 2 flavours: full, automation 2 build types: release, debug I'm in the process of migrating everything to kotlin. Module structure commons [android library] (works as expected with test coverage) client-test-support (used for test implementations

Kotlin filter lambda array using iteration index

北城余情 提交于 2021-02-07 12:19:01
问题 I would like to filter an array into an array of every nth item. For examples: fun getNth(array: Array<Any>, n: Int): Array<Any> { val newList = ArrayList<Any>() for (i in 0..array.size) { if (i % n == 0) { newList.add(array[i]) } } return newList.toArray() } Is there an idiomatic way to do this using for example Kotlin's .filter() and without A) provisioning a new ArrayList and B) manually iterating with a for/in loop? 回答1: filterIndexed function is suited exactly for this case: array

Kotlin filter lambda array using iteration index

孤街醉人 提交于 2021-02-07 12:17:33
问题 I would like to filter an array into an array of every nth item. For examples: fun getNth(array: Array<Any>, n: Int): Array<Any> { val newList = ArrayList<Any>() for (i in 0..array.size) { if (i % n == 0) { newList.add(array[i]) } } return newList.toArray() } Is there an idiomatic way to do this using for example Kotlin's .filter() and without A) provisioning a new ArrayList and B) manually iterating with a for/in loop? 回答1: filterIndexed function is suited exactly for this case: array

Kotlin filter lambda array using iteration index

北城以北 提交于 2021-02-07 12:17:05
问题 I would like to filter an array into an array of every nth item. For examples: fun getNth(array: Array<Any>, n: Int): Array<Any> { val newList = ArrayList<Any>() for (i in 0..array.size) { if (i % n == 0) { newList.add(array[i]) } } return newList.toArray() } Is there an idiomatic way to do this using for example Kotlin's .filter() and without A) provisioning a new ArrayList and B) manually iterating with a for/in loop? 回答1: filterIndexed function is suited exactly for this case: array

spring.config.location not working on spring boot 2.0.0 M6

蹲街弑〆低调 提交于 2021-02-07 11:32:25
问题 I'm migrating one of my micro-services to Spring Boot 2.0.0.M6 and I got and error while using the --spring.config.location= option on the command line. The error is the following: Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'property' in value "${property}" at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172) ~[spring-core-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.util

Does Kotlin support monadic comprehension?

穿精又带淫゛_ 提交于 2021-02-07 11:23:14
问题 Like LINQ in C#, for comprehension in Scala, anything similar in Kotlin? If not supported, is it planned? 回答1: There is no special keyword (do/for) and so no direct translation to nested flatMap (desugaring) like in other languages. But monadic comprehension can be implemented with coroutines. From Arrow documentation : https://arrow-kt.io/docs/patterns/monad_comprehensions/#comprehensions-over-coroutines Comprehensions over coroutines This feature is known with multiple names: async/await,

Customising accessibility in recyclerview using onPopulateAccessibilityEvent and AccessibilityDelegate

不羁岁月 提交于 2021-02-07 10:38:19
问题 I'm trying to customise the talkback output for items in a RecyclerView. I have modified the onBindViewHolder method to include the following code itemView?.setAccessibilityDelegate(object: View.AccessibilityDelegate() { override fun onPopulateAccessibilityEvent(host: View?, event: AccessibilityEvent?) { super.onPopulateAccessibilityEvent(host, event) event?.let {event -> if (event.eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) { event.text.add("Hello world!") } } } })

Generics and inheritance in Java library used from Kotlin

痴心易碎 提交于 2021-02-07 10:25:44
问题 I'm having problem implementing a Kotlin class which uses Java-defined generics/interfaces classes from MockMvc library. Library classes: public interface ConfigurableMockMvcBuilder<B extends ConfigurableMockMvcBuilder<B>> extends MockMvcBuilder { // ... <T extends B> T defaultRequest(RequestBuilder requestBuilder); // ... } @FunctionalInterface public interface MockMvcBuilderCustomizer { /** * Customize the given {@code builder}. * @param builder the builder */ void customize

Generics and inheritance in Java library used from Kotlin

夙愿已清 提交于 2021-02-07 10:25:23
问题 I'm having problem implementing a Kotlin class which uses Java-defined generics/interfaces classes from MockMvc library. Library classes: public interface ConfigurableMockMvcBuilder<B extends ConfigurableMockMvcBuilder<B>> extends MockMvcBuilder { // ... <T extends B> T defaultRequest(RequestBuilder requestBuilder); // ... } @FunctionalInterface public interface MockMvcBuilderCustomizer { /** * Customize the given {@code builder}. * @param builder the builder */ void customize

Kafka Join not firing after re-key

烈酒焚心 提交于 2021-02-07 09:44:03
问题 I'm working on a Kafka streams application written in Kotlin, and I'm seeing some bizarre behavior with a join. At a high level, I'm streaming two topics with different keys. However, I can rekey one of the messages so that they keys line up. After I do this though, the subsequent join is not fired. Below I have supplied the simplified code (with irrelevant portions elided and replaced with comments) val builder = KStreamBuilder() val joinWindow = JoinWindows.of(/* 30 days */).until(/* 365