1

Does it mean list item can be String or non String? I find the usage in following code:

class KotlinGreetingJoiner(val greeter: Greeter) {

    val names = ArrayList<String?>()

    fun addName(name: String?) {
        names.add(name)
    }

    fun getJoinedGreeting(): String {
        val joiner = Joiner.on(" and ").skipNulls()
        return "${greeter.getGreeting()} ${joiner.join(names)}"
    }
}
Mibac
  • 8,990
  • 5
  • 33
  • 57
pozklundw
  • 505
  • 1
  • 9
  • 16
  • 4
    Maybe we should mark this question as duplicate of https://stackoverflow.com/questions/34498562/in-kotlin-what-is-the-idiomatic-way-to-deal-with-nullable-values-referencing-o – Ruslan Jan 04 '16 at 16:21

1 Answers1

14

It means the list elements can be either String or null. This is covered under Null Safety in the documentation.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Emil Laine
  • 41,598
  • 9
  • 101
  • 157
  • 3
    see also: https://stackoverflow.com/questions/34498562 for dealing with null values. Also note that `filterNotNull()` method is available on Kotlin collections that let's you eliminate the `null` values if desired or convert to a list that is no longer capable of having nulls. – Jayson Minard Jan 04 '16 at 17:39