kotlin

Testing Coroutines runBlockingTest time

泄露秘密 提交于 2021-01-28 06:02:43
问题 Using this manual to test Coroutines using runBlockingTest . I encountered some issues. If the coroutine created by launch or async calls delay then the runBlockingTest will not auto-progress time right away. This allows tests to observe the interaction of multiple coroutines with different delays. @Test fun testFooWithLaunchAndDelay() = runBlockingTest { foo() // the coroutine launched by foo has not completed here, it is suspended waiting for delay(1_000) advanceTimeBy(1_000) // progress

API data in kotlin fragment

独自空忆成欢 提交于 2021-01-28 06:01:46
问题 I am trying to use Drawer activity , seems that it has 3 files to just show simple text as This is home Fragment :| Anyway, I have tracked back all those files and found fragment_home.xml , HomeFragment.kt and HomeViewModel.kt Question How should I call for API data trough fragments? Code my code Based on android studio documentation this is the code that I should use in order to get my api data. val textView = findViewById<TextView>(R.id.TextView) // Instantiate the RequestQueue. val queue =

Android Studio - Could not find org.jetbrains.kotlin:kotlin-stdlib:1.1.3-2

社会主义新天地 提交于 2021-01-28 05:34:22
问题 I was tring to compile my project in Android Studio (using Java) and the following error appeared: Could not find org.jetbrains.kotlin:kotlin-stdlib:1.1.3-2. Searched in the following locations: - https://maven.fabric.io/public/org/jetbrains/kotlin/kotlin-stdlib/1.1.3-2/kotlin-stdlib-1.1.3-2.pom - https://maven.fabric.io/public/org/jetbrains/kotlin/kotlin-stdlib/1.1.3-2/kotlin-stdlib-1.1.3-2.jar - https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-stdlib/1.1.3-2/kotlin-stdlib

Jooq fetchInto class java.util.LinkedHashMap cannot be cast to class

随声附和 提交于 2021-01-28 04:45:41
问题 Giving the last example given in this SO thread. I get this error: java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class com.example.dtos.UserElement (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; com.example.dtos.UserElement is in unnamed module of loader 'app') Am I supposed to use a special mapper that jooq will be happy with? Any help is welcome Edit: Jooq version: 3.14.3 Postgres: 11 ctx.select( USERS.ID.`as`("id"), USERS.USERNAME.`as

How to implement parallel mapping for sequences in kotlin

天大地大妈咪最大 提交于 2021-01-28 04:40:54
问题 I'm trying to implement a parallel implementation for both Iterable and Sequence in Kotlin. I got a little file, it consists of 4 extension functions, but the third one gives me an compiler error: suspend fun <T, R> Iterable<T>.parallelMap(block: suspend(T) -> R) = coroutineScope { map { async { block(it) } }.map { it.await() } } suspend fun <T> Iterable<T>.parallelForEach(block: suspend (T) -> Unit) = coroutineScope { map { async { block(it) } }.forEach { it.await() } } suspend fun <T, R>

Retrieve annotations from KType

对着背影说爱祢 提交于 2021-01-28 03:24:37
问题 I have a simple TYPE_USE annotation: @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) public @interface Cool { } And the following sample Kotlin class: class Item( id: Long? = null, var names: List<@Cool String> = emptyList()) Is there any way to extract the annotation using Java reflection? Item.class.getMethod("getName").getAnnotatedReturnType() loses the annotations, same with getting the field. Can I even get the annotation from Kotlin? Item:

How to save LocalData in Firebase Realtime database?

懵懂的女人 提交于 2021-01-28 03:24:16
问题 I am very new using Kotlin and programming and I am currently making a calendar with events. My problem comes when I want to connect these events to firebase. I am using an example that I found in git (https://github.com/kizitonwose/CalendarView) that uses the ThreeTen library for dates. This is the Event object: class Event (val id: String, val text: String, val date: LocalDate) : Serializable The data variable is of the LocalData type and this is what is causing me problems since it seems

Android Kotlin / JAVA - get current world time / UTC in seconds since 1970

北战南征 提交于 2021-01-28 03:15:52
问题 As the title says I need the current workd time in seconds since 1970. This is what I've tried so far: System.currentTimeMillis() and val df = DateFormat.getTimeInstance() df.setTimeZone(TimeZone.getTimeZone("gmt")) val gmtTime = df.format(Date()) But both are showing the time which is based on the phone time, so when a user changes the phone time manually it will be affected Is there a way to get the current workd time in seconds without using an extern API? 回答1: No, the only way to get time

Kotlin infers JOOQ methods wrong

北城以北 提交于 2021-01-28 02:20:16
问题 Given a system using Kotlin version 1.3.61 and JOOQ version 3.13.1, a method like this builds an union query normally: val selectCommonPart = coalesce(sum(field(name("amount"), Long::class.java)), ZERO) .`as`(field(name("totalAmount"))) var whereCommonPart: Condition = trueCondition().and(field(name("Id")).eq(Id)) // Id comes as a parameter var query = dsl.selectQuery() query.addSelect(selectCommonPart) query.addFrom(table("${tableName(startDate)}")) // `startDate` is a `LocalDate`,

override function with concrete type parameter

為{幸葍}努か 提交于 2021-01-28 02:00:28
问题 Hi I would like know why the following example doesn't work abstract class BaseClass { } class ConcretClasOne : BaseCalculator { } class ConcretClasTwo : BaseCalculator { } abstract class BaseRun { abstract fun run(param: BaseClass): Int } class ConcretRun : BaseRun { override fun run(param: ConcretClasOne): Int { return 0 } } this shows me a message run overrides nothing . I suppose that kotlin isn't able to match the abstract class and the concrete implementation, but what other alternative