Skip to content

Instantly share code, notes, and snippets.

<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Choir {
private val singers = mutableListOf<Singer>()
fun addSinger(singer: Singer) {
singers.add(singer)
}
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Choir {
private val singers = mutableListOf<Singer>()
operator fun plusAssign(singer: Singer) {
singers.add(singer)
}
}
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
data class Singer(val name: String)
fun main() {
val choir = Choir()
val singerMeghan = Singer("Meghan")
choir += singerMeghan
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
operator fun contains(s: Singer) : Boolean {
return singers.contains(s)
}
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
data class Singer(val name: String)
fun main() {
val choir = Choir()
val singerMeghan = Singer("Meghan")
choir += singerMeghan
if(singerMeghan in choir){
println("Meghan is a part of the choir!")
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
val choir = Choir()
val singerMeghan = Singer("Meghan")
choir += singerMeghan
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
Choir choir = new Choir();
Singer singerMeghan = new Singer("Meghan");
choir.plusAssign(singerMeghan);
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
Choir choir = new Choir();
Singer singerMeghan = new Singer("Meghan");
choir.plusAssign(singerMeghan);
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Datasource(val context: Context) {
fun getFlowerList(): Array<String> {
return context.resources.getStringArray(R.array.flower_array)
}
}
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"