How does erasure work in Kotlin?

Actually Kotlin knows the difference between the two methods in your example, but jvm will not. That’s why it’s a “platform” clash. You can make your second example compile by using the @JvmName annotation: class Foo { @JvmName(“barString”) fun bar(foo: List<String>): String { return “” } @JvmName(“barInt”) fun bar(foo: List<Int>): String { return “2”; } … Read more

Static data in Kotlin

You can use Kotlin bytecode viewer to find out what these options are compiled to. With Kotlin 1.0.2 the compiled bytecode shows that val property in object or companion object is compiled into a private static final field inside the class: // access flags 0x1A private final static I FILES_TO_DOWNLOAD = 100 and a getter, … Read more

How to Lazy Initialize with a parameter in Kotlin

You can use any element within the accessible scope, that is constructor parameters, properties, and functions. You can even use other lazy properties, which can be quite useful sometimes. Here are all three variant in a single piece of code. abstract class Class<V>(viewInterface: V) { private val anotherViewInterface: V by lazy { createViewInterface() } val … Read more

Overriding equals in Kotlin

I’m not certain of the reason for this error, but it might be related to a deeper problem with your approach… In Kotlin (and Java), the equals() method has a fairly tight specification.  One condition is that it must be symmetric: whenever a and b are not null, a.equals(b) must always give the same result … Read more

asReversed() vs reversed() in Kotlin?

In Kotlin, both reversed and asReversed have their own unique functions. The Reverse function returns a list with elements in reversed: order. Reversed Function Whereas, the asReversed function returns a reversed read-only view of the original List i.e., all changes made in the original list will be reflected in the reversed one. asReversed Function The … Read more

Is `a?.let{} ?: run{}` idiomatic in Kotlin?

It’s dangerous to conflate foo?.let { bar(it) } ?: baz() with if (foo != null) bar(foo) else baz(). Say you have a function: fun computeElements(): List<Int>? = emptyList() Consider this code: val maxElement = computeElements()?.let { it.max() } ?: return println(“Max element was $maxElement”) Compared to: val list: List<Int>? = computeElements() val maxElement = if … Read more

How to call suspend function from Service Android?

You can create your own CoroutineScope with a SupervisorJob that you can cancel in the onDestroy() method. The coroutines created with this scope will live as long as your Service is being used. Once onDestroy() of your service is called, all coroutines started with this scope will be cancelled. class YourService : Service() { private … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)