Eugen Martynov
10/03/2024, 2:24 PMAny?.toString()
method. Are there original thoughts why it is there? Except of logging, are there other use cases? Especially println(null)
and println(null.toString())
are looking same in console.Joffrey
10/03/2024, 2:26 PMprintln(x)
calls x.toString()
to know what to print, so without Any?.toString()
you would only have println(String)
and you would need to explicitly convert things to strings before you can print or interpolate themSam
10/03/2024, 2:27 PMAny?.toString()
cause many bugs, I'd rather it not existJoffrey
10/03/2024, 2:28 PMStringable
or Printable
interface, instead of giving this function to Any?
(or rather Object
, because it definitely comes from Java)Eugen Martynov
10/03/2024, 2:30 PMJoffrey
10/03/2024, 2:30 PMEugen Martynov
10/03/2024, 2:33 PMprintln()
is Kotlin funcionSam
10/03/2024, 2:34 PMnull.toString()
. In Java it's a runtime error; in Kotlin it's `"null"`—which is the bit that I object to, since it causes bugs and surprisesSam
10/03/2024, 2:35 PMtoString()
in general, but not necessarily for the nullable overload that Kotlin adds on topJavier
10/03/2024, 2:35 PMJavier
10/03/2024, 2:35 PMJoffrey
10/03/2024, 2:36 PMx.something()
may be safe on nullable stuff - it doesn't look/feel right.Joffrey
10/03/2024, 2:37 PMEugen Martynov
10/03/2024, 3:13 PMList<*>?.orEmpty()
quite usefulJoffrey
10/03/2024, 3:14 PM.
syntax hides the fact that it's nullable when skimming through the code, and I find it confusing. I much prefer ?: emptyList()
in most casesokarm
10/03/2024, 3:20 PM.orEmpty
and more generally .orDefault(X)
has become a standard Kotlin convention IMO. Maybe when Kotlin was new it could have "hidden the fact that it's nullable", but now it's standard naming. Similar to toList
(creates a new list) vs asList
(wraps, does not allocate a new list)Joffrey
10/03/2024, 3:21 PMtoX()
vs asX()
, thoughRob Elliot
10/03/2024, 9:11 PM