kotlin-interop

How to disable @NonNull/@Nullable annotations in Kotlin generated Java code

不问归期 提交于 2021-01-29 09:11:40
问题 I need to disable @NonNull/@Nullable annotations in Kotlin generated Java code because some annotation adapters (code generators) cant handle properly some annotated fields Do you know how it could be done? Some Kotlin annotation or compilator directive Problem: kotlin class: open class TestModel( var test: ByteArray = ByteArray(0) ) generated java: public class TestModel { @org.jetbrains.annotations.NotNull() private byte[] test; @org.jetbrains.annotations.NotNull() public final byte[]

Changing kotlin extension function receiver JVM name

久未见 提交于 2021-01-27 04:30:34
问题 This is a general question. Let's say I have an extension function written in kotlin which converts DP to PX and return a NonNull Int fun Int.toPx() { /** implementation */ } The function in java will look something like this public int toPx(int $receiver) { /** implementation */ } In my opinion the $receiver makes the Java-interop feels generated and uninviting. I know that you can use the @JvmName annotation with some combinations like @file:JvmName to change the name in java. When i'm

Data classes in Kotlin

落花浮王杯 提交于 2020-07-05 08:24:11
问题 What is the difference between: definition 1 data class Person (var name:String, var age:Int) definition 2 class Person (var name:String, var age:Int) definition 3 class Person (){ var name:String = "" var age:Int = 1 } In the 3 cases when i use the autocomplete i saw the same methods availables like a POJO... is the same but 3 differents ways? 回答1: Difference in equals , hashCode , & toString the most important difference between definition 1 and definitions 2 & 3 is that in definition 1 ,

Kotlin use Java callback interface

别等时光非礼了梦想. 提交于 2020-02-27 23:15:05
问题 I have a WebView. I want to call public void evaluateJavascript(String script, ValueCallback<String> resultCallback) this method. Here is the ValueCallback interface: public interface ValueCallback<T> { /** * Invoked when the value is available. * @param value The value. */ public void onReceiveValue(T value); }; Here is my kotlin code: webView.evaluateJavascript("a", ValueCallback<String> { // cant override function }) Anyone have idea to override the onReceiveValue method in kotlin? I tried

Null safety in legacy Java libraries used in Kotlin projects

雨燕双飞 提交于 2020-02-03 10:57:48
问题 Let's say I have particular code in old/legacy Java library: public class JavaClass { private String notNullString; private String nullableString; private String unannotatedString; public JavaClass(@NotNull String notNullString, @Nullable String nullableString, String unannotatedString) { this.notNullString = notNullString; this.nullableString = nullableString; this.unannotatedString = unannotatedString; } @NotNull public String getNotNullString() { return notNullString; } @Nullable public

Kotlin native interop linker could not find framework

本小妞迷上赌 提交于 2020-01-22 20:47:22
问题 I'm trying to use cocoapods framework in Kotlin Multiplatform project. So I added framework to Pods file. ran pod install. created .def file added cinterop config in build.gradle ./gradlew cinteropFirebaseIos runs successfully. It generates .klib so I can see classes in kotlin code. But when I'm trying to run iOS app build fails with message: Showing Recent Messages > Task :app:linkDebugFrameworkIos ld: framework not found FirebaseDatabase /Applications/Xcode.app/Contents/Developer/Toolchains

Kotlin dagger 2 Android ViewModel injection error

穿精又带淫゛_ 提交于 2020-01-12 10:12:02
问题 I'm trying to use dagger 2 on my Android application to inject the new ViewModel from arch android library. From what I see on this sample https://github.com/googlesamples/android-architecture-components/tree/e33782ba54ebe87f7e21e03542230695bc893818/GithubBrowserSample I need to use this: @MustBeDocumented @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) @Retention(AnnotationRetention.RUNTIME) @MapKey internal

Kotlin dagger 2 Android ViewModel injection error

余生颓废 提交于 2020-01-12 10:10:31
问题 I'm trying to use dagger 2 on my Android application to inject the new ViewModel from arch android library. From what I see on this sample https://github.com/googlesamples/android-architecture-components/tree/e33782ba54ebe87f7e21e03542230695bc893818/GithubBrowserSample I need to use this: @MustBeDocumented @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) @Retention(AnnotationRetention.RUNTIME) @MapKey internal

Jinq in Kotlin - how to convert lambda into java SerializedLambda?

烂漫一生 提交于 2020-01-05 04:28:08
问题 Can I have serializable lambda in Kotlin? I am trying to use Jinq library from Kotlin, but it requires serializable lambdas. Is there any syntax that makes it possible? Update: My code: var temp=anyDao.streamAll(Task::class.java) .where<Exception,Task> { t->t.taskStatus== TaskStatus.accepted } .collect(Collectors.toList<Task>()); I am getting this error: Caused by: java.lang.IllegalArgumentException: Could not extract code from lambda. This error sometimes occurs because your lambda

kotlin - non null mark for platform types / methods

梦想与她 提交于 2019-12-24 07:18:25
问题 I often use UUID.randomUUID() . Type inferred by kotlin is UUID! . is there any way to tell kotlin that return type of this specific method is UUID and is always non null? or do i have to do everywhere UUID.randomUUID()!! or implement my own method? 回答1: If you explicitly declare the types, it should declare them non-nullable instead of as a platform type. val id1 = UUID.randomUUID() // UUID! val id2: UUID = UUID.randomUUID() // UUID I do this with a function to make things a bit easier. By