Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin: isNullOrEmpty vs TextUtils.isEmpty

In Kotlin (Android project), which is preferable to use ?

isNullOrEmpty or TextUtils.isEmpty and why

I believe they do the exact thing and are "null" safe, right ?

like image 702
thahgr Avatar asked Dec 07 '22 11:12

thahgr


1 Answers

Based off of my question here

If your project will be ported to other frameworks, making use of isNullOrEmpty will probably result in a safer experience, because it's based on Kotlin (specifically package kotlin.text) and not on package android.text;

Why is this safer ?

Well, the implementation of isNullOrEmpty might change depending on the platform but it will be available to use and is part of Kotlin, compared to TextUtils.isEmpty being only for android.

like image 112
a_local_nobody Avatar answered Dec 28 '22 06:12

a_local_nobody