* true if any element in is found in the receiving collection.įun Collection. * elements the elements to look for in the receiving collection. * Returns true if the receiving collection contains any of the specified elements. Here's an example implementation of an extension function defined on the Collection class, the details of which are inspired by other answers in this thread: /** Constructors Common JVM JS Native 1.0 The root of the Kotlin class hierarchy.Every Kotlin class has Any as a superclass. The implementation detail is tucked away inside of that function and can be changed in a single place in future should you wish to change the implementation. Any - Kotlin Programming Language Common JVM JS Native Version 1.8 kotlin-stdlib / kotlin / Any Any Common JVM JS Native 1.0 open class Any (Common source) (Native source) The root of the Kotlin class hierarchy. All of the places where you need to check whether an Array or Collection contains any of the elements of another then remains nice and neat, as follows: arrayOf(1, 2, 3).containsAny(2, 3) For example, if we create a Set and put a few strings into it, at runtime weâre only able to see it as a Set.That is, an instance of a generic class doesnât preserve its type parameters at runtime. For me, the best way to solve this is to define a containsAny(elements:) extension function on the Array and/or Collection class. Kotlin List.any () Examples Kotlin List.any () The Kotlin List. As with Java, Kotlinâs generics are erased at runtime.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |