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 idiomatically test for non-null, non-empty strings in Kotlin?

You can use isNullOrEmpty or its friend isNullOrBlank like so: if(!s.isNullOrEmpty()){ // s is not empty } Both isNullOrEmpty and isNullOrBlank are extension methods on CharSequence? thus you can use them safely with null. Alternatively turn null into false like so: if(s?.isNotEmpty() ?: false){ // s is not empty } you can also do the … Read more

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