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,120
  • 4
  • 33
  • 56
pozklundw
  • 477
  • 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
  • 959,406
  • 173
  • 1,780
  • 1,769
emlai
  • 39,703
  • 9
  • 98
  • 145
  • 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