# data class

Published articles for data class.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Beyond Positions: Kotlin's New Name-Based Destructuring

DevFeed: [Beyond Positions: Kotlin's New Name-Based Destructuring](<https://devfeed.tech/articles/beyond-positions-kotlin-s-new-name-based-destructuring-25979.md>)

Original publisher: [Read original article](<https://proandroiddev.com/beyond-positions-kotlins-new-name-based-destructuring-eee347d1bb5c?source=rss-711ab22c5c77------2>)

Author: Nav Singh

Published: 2026-03-18T01:24:50Z

Content type: tutorial

Language: en

Sources: [Stories by Nav Singh 🇨🇦 on Medium](<https://devfeed.tech/sources/stories-by-nav-singh-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [properties](<https://devfeed.tech/topics/properties.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-2](<https://devfeed.tech/tags/kotlin-2.md>), [kotlin-native](<https://devfeed.tech/tags/kotlin-native.md>), [properties](<https://devfeed.tech/tags/properties.md>)

### AI overview

This tutorial explains Kotlin 2.3.20's experimental name-based destructuring declarations, which match variables to properties instead of relying on componentN() position. It also covers the compiler option and supported modes.

### Source excerpt

Image generated using Perplexity Name-based destructuring declarations were introduced in Kotlin 2.3.20 and match variables to properties rather than relying on position-based componentN(). Previously, destructive declarations used position-based destruction: data class User(var firstName: String, var lastName: String) val user = User("Alice", "Husseini") // componentN() val(firstName,lastName) = user println(firstName) println(lastName)Drawback of the componentN() based approach Destructuring relies on the order of componentN() functions, lastName receives the value of firstName, and firstName receives the value of lastName 👇 data class User(var firstName: String, var lastName: String) val user = User("Alice", "Husseini") // componentN() val(lastName,firstName) = user println(firstName) -> Husseini println(lastName) -> AliceName-based destructuring ✨ It's an Experimental feature. We can control how the compiler interprets destructuring declarations with the -Xname-based-destructuring compiler option. kotlin { // .. compilerOptions { freeCompilerArgs.add("-Xname-based-destructuring=only-syntax") } }Each variable refers to a property by name.val user = User("Alice", "Husseini") // Name-based destructuring (val firstName = firstName, val lastName = lastName) = userModeshttps://kotlinlang.org/docs/whatsnew2320.html#languageMode -- Name-Mismatch⚠ Warning ⚠Name-Mismatch warningMode -- Complete Position-based destructuring using square brackets []: data class User(var firstName: String, var lastName: String) val user = User("Alice", "Husseini") // componentN() val [firstName,lastName] = userReferences What's new in Kotlin 2.3.20 | Kotlin Stay in touch https://www.linkedin.com/in/navczydev/ JavaScript is not available. navczydev - Overview navczydev.bsky.social Beyond Positions: Kotlin's New Name-Based Destructuring was originally published in ProAndroidDev on Medium, where people are continuing the conversation by highlighting and responding to this story.

## 5 Kotlin Internals You Should Know

DevFeed: [5 Kotlin Internals You Should Know](<https://devfeed.tech/articles/5-kotlin-internals-you-should-know-25917.md>)

Original publisher: [Read original article](<https://proandroiddev.com/5-kotlin-internals-you-should-know-d4bab319d4ef?source=rss-9bb203a4ab2e------2>)

Author: Jaewoong Eum

Published: 2026-02-17T01:29:40Z

Content type: article

Language: en

Sources: [Stories by Jaewoong Eum on Medium](<https://devfeed.tech/sources/stories-by-jaewoong-eum-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [analysis](<https://devfeed.tech/tags/analysis.md>), [android](<https://devfeed.tech/tags/android.md>), [article](<https://devfeed.tech/tags/article.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-coroutines](<https://devfeed.tech/tags/kotlin-coroutines.md>), [programming](<https://devfeed.tech/tags/programming.md>)

### AI overview

This article explains five Kotlin internals: compiler-generated methods for data classes, thread-safety strategies used by lazy delegates, type erasure for value classes, hidden allocations from higher-order functions and their removal through inline functions, and the JVM compilation of extension functions.

### Source excerpt

Unsplash@mrsimonfischer Kotlin makes writing clean, expressive code feel effortless. Features like data classes, lazy properties, and extension functions save you from the boilerplate that Java developers deal with daily. But behind every concise Kotlin feature is a compiler performing real work, generating bytecode, managing thread safety, and making allocation decisions on your behalf. Understanding what the compiler actually produces helps you write more performant code and make better design decisions. In this article, you'll explore five Kotlin internals that most developers should know, revealing what really happens when the compiler transforms your code. You'll examine how a single line data class expands into a full suite of generated methods, how the lazy delegate implements three distinct thread safety strategies, how value class achieves zero cost type safety through erasure, how higher order functions create hidden object allocations (and how inline eliminates them), and how extension functions compile to static methods on the JVM. These insights originate from Practical Kotlin Deep Dive, a book that explores 70 Kotlin topics at this level of depth and The Course: Practical Kotlin Deep Dive, covering the language fundamentals, standard library, coroutines, compiler internals, and Kotlin Multiplatform. Each section below is a window into the kind of "Pro Tips for Mastery" analysis you'll find throughout the book and course. 1. Data class: One line, six generated methods Most developers know that data class auto-generates equals(), hashCode(), and toString(). But the full scope of what the compiler produces from a single line is worth seeing firsthand. Start with this Kotlin class: https://medium.com/media/b1b28a62953d8d21ec6bb27a95216361/href One line. Two properties. Now look at what the Kotlin compiler generates when this is decompiled into Java bytecode: https://medium.com/media/a9bbcc4370d6da0f974bf53f903967f9/href The data keyword is an instruction t

## UI State, Callbacks and Equality Pitfalls

DevFeed: [UI State, Callbacks and Equality Pitfalls](<https://devfeed.tech/articles/ui-state-callbacks-and-equality-pitfalls-25875.md>)

Original publisher: [Read original article](<http://lordraydenmk.github.io//2024/ui-state-callbacks/>)

Author: Stojan Anastasov

Published: 2024-11-30T00:00:00Z

Content type: tutorial

Language: en

Sources: [Stojan Anastasov's blog](<https://devfeed.tech/sources/stojan-anastasov-s-blog.md>)

Topics: [ui](<https://devfeed.tech/topics/ui.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Code](<https://devfeed.tech/topics/code.md>), [data](<https://devfeed.tech/topics/data.md>), [Compose](<https://devfeed.tech/topics/compose.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [code](<https://devfeed.tech/tags/code.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [pitfalls](<https://devfeed.tech/tags/pitfalls.md>), [sealed-class](<https://devfeed.tech/tags/sealed-class.md>), [state](<https://devfeed.tech/tags/state.md>), [ui](<https://devfeed.tech/tags/ui.md>)

### AI overview

This Kotlin article examines how callback functions embedded in UI state data classes can produce surprising equality results because function equality depends on reference identity. It explains the resulting update and performance issues in unidirectional data flow and discusses alternatives that keep action logic in the ViewModel or Presenter.

### Source excerpt

Yesterday a friend asked me to review his blog post on Function Properties in Data Classes are Code Smells. We then discussed how we would solve the issue in the context of UI state and callbacks. And I thought it might be useful to write it in form of a blog post. An example To better explain the problem, I'll start with a sample app I'm maintaining. It shows a list of superheroes from the Marvel API. See the screenshot below. Currently the UI state is modeled like: data class SuperheroViewEntity( val id: Long, val name: String, val imageUrl: HttpUrl ) Content( val superheroes: List<SuperheroViewEntity>, val copyright: String, ) // some states omitted for brevity A Naive Solution Let's say we have a new requirement, we want to add a favorite button to each superhero so we can keep track of our favorite superheroes. To do that we will introduce some functions: // ViewModel/Presenter fun onAddToFavorites(superheroId: Long) = TODO() fun onRemoveFromFavorites(superheroId: Long) = TODO() These functions can be part of the ViewModel/Presenter that delegates to a repository to store the IDs. Note: In this example, the ViewModel/Presenter use a single function per action the view can take. The technique described here also works with a single function + a sealed class for individual actions. To achieve this we might be tempted to update our SuperheroViewEntity to include: data class SuperheroViewEntity( val id: Long, val name: String, val imageUrl: HttpUrl, val onFavoriteClicked: () -> Unit ) // ViewModel fun Superhero.toViewEntity() = SuperheroViewEntity( id, name, imageUrl, if (favorite) { onRemoveFromFavorites(id) } else { onAddToFavorites(id) } ) // View layer Modifier.clickable { entity.onFavoriteClicked() } However this approach has some significant drawbacks. Functions in Kotlin are equal only if they are the same reference. val fa = { println(1) } val fb = { println(1) } println(fa == fb) // false, does the same job, but different reference val fc = fa println(fc =

## A Curious Case of Mistaken Identity: How Lambdas Break Data Class Hashing

DevFeed: [A Curious Case of Mistaken Identity: How Lambdas Break Data Class Hashing](<https://devfeed.tech/articles/a-curious-case-of-mistaken-identity-how-lambdas-break-data-class-hashing-27333.md>)

Original publisher: [Read original article](<https://blog.mmckenna.me/a-curious-case-of-mistaken-identity>)

Author: Matt McKenna

Published: 2024-11-14T21:44:31Z

Content type: tutorial

Language: en

Sources: [Matt McKenna](<https://devfeed.tech/sources/matt-mckenna.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [hashing](<https://devfeed.tech/topics/hashing.md>), [hash](<https://devfeed.tech/topics/hash.md>), [consistency](<https://devfeed.tech/topics/consistency.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [behavior](<https://devfeed.tech/tags/behavior.md>), [class](<https://devfeed.tech/tags/class.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [hashcode](<https://devfeed.tech/tags/hashcode.md>), [hashing](<https://devfeed.tech/tags/hashing.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [maintenance](<https://devfeed.tech/tags/maintenance.md>)

### AI overview

This Kotlin article explains why data class instances containing lambdas may compare as unequal and produce different hash-based behavior. Each lambda instance has a distinct identity, so the article recommends excluding the callback from equality and hashCode calculations, while noting the resulting maintenance cost.

### Source excerpt

Introduction: The Scene of the Crime It was a dark and stormy night. My hands were flying across the keys when suddenly the codebase began to exhibit strange behavior. Hashes, which once returned the same values for identical objects, suddenly became...

## Avoid the Long Parameter List

DevFeed: [Avoid the Long Parameter List](<https://devfeed.tech/articles/avoid-the-long-parameter-list-23855.md>)

Original publisher: [Read original article](<http://testing.googleblog.com/2024/05/avoid-long-parameter-list.html>)

Author: Google Testing Bloggers (noreply@blogger.com)

Published: 2024-05-20T13:42:00Z

Content type: tutorial

Language: en

Sources: [Google Testing Blog](<https://devfeed.tech/sources/google-testing-blog.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [Java](<https://devfeed.tech/topics/java.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Python](<https://devfeed.tech/topics/python.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [class](<https://devfeed.tech/tags/class.md>), [code](<https://devfeed.tech/tags/code.md>), [code-health](<https://devfeed.tech/tags/code-health.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [gene-volovich](<https://devfeed.tech/tags/gene-volovich.md>), [google](<https://devfeed.tech/tags/google.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [language](<https://devfeed.tech/tags/language.md>), [list](<https://devfeed.tech/tags/list.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [post](<https://devfeed.tech/tags/post.md>), [python](<https://devfeed.tech/tags/python.md>), [series](<https://devfeed.tech/tags/series.md>), [tott](<https://devfeed.tech/tags/tott.md>)

### AI overview

This Google Code Health article explains how long parameter lists make method calls difficult to understand and maintain. It recommends grouping related parameters into meaningful value objects, with language-specific options including Java records, Kotlin data classes, C++ option structs, Python keyword arguments and defaults, and the Java Builder pattern.

### Source excerpt

This is another post in our Code Health series. A version of this post originally appeared in Google bathrooms worldwide as a Google Testing on the Toilet episode. You can download a printer-friendly version to display in your office. By Gene Volovich Have you seen code like this? void transform(String fileIn, String fileOut, String separatorIn, String separatorOut); This seems simple enough, but it can be difficult to remember the parameter ordering. It gets worse if you add more parameters (e.g., to specify the encoding, or to email the resulting file): void transform(String fileIn, String fileOut, String separatorIn, String separatorOut, String encoding, String mailTo, String mailSubject, String mailTemplate); To make the change, will you add another (overloaded) transform method? Or add more parameters to the existing method, and update every single call to transform? Neither seems satisfactory. One solution is to encapsulate groups of the parameters into meaningful objects. The CsvFile class used here is a "value object" -- simply a holder for the data. class CsvFile { CsvFile(String filename, String separator, String encoding) { ... } String filename() { return filename; } String separator() { return separator; } String encoding() { return encoding; } } // ... and do the same for the EmailMessage class void transform(CsvFile src, CsvFile target, EmailMessage resultMsg) { ... } How to define a value object varies by language. For example, in Java, you can use a record class, which is available in Java 16+ (for older versions of Java, you can use AutoValue to generate code for the value object); in Kotlin, you can use a data class; in C++, you can use an option struct. Using a value object this way may still result in a long parameter list when instantiating it. Solutions for this vary by language. For example, in Python, you can use keyword arguments and default parameter values to shorten the parameter list; in Java, one option is to use the Builder pattern, wh

## Data classes in Kotlin

DevFeed: [Data classes in Kotlin](<https://devfeed.tech/articles/data-classes-in-kotlin-39329.md>)

Original publisher: [Read original article](<https://kt.academy/article/kfde-data>)

Published: 2023-11-13T00:01:00Z

Content type: tutorial

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [classes](<https://devfeed.tech/topics/classes.md>), [data](<https://devfeed.tech/topics/data.md>)

Tags: [classes](<https://devfeed.tech/tags/classes.md>), [code](<https://devfeed.tech/tags/code.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [type](<https://devfeed.tech/tags/type.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This tutorial explains Kotlin data classes, including how they differ from regular classes and how the compiler generates methods such as equals, hashCode, toString, and component functions. It also discusses inherited object behavior and when custom overrides are typically unnecessary.

### Source excerpt

What are data classes in Kotlin and how do we use them.

## Data Classes and Destructuring

DevFeed: [Data Classes and Destructuring](<https://devfeed.tech/articles/data-classes-and-destructuring-25052.md>)

Original publisher: [Read original article](<https://typealias.com/start/kotlin-data-classes-and-destructuring/>)

Author: author@typealias.com (Dave Leeds)

Published: 2023-10-09T00:00:00Z

Content type: tutorial

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [data](<https://devfeed.tech/topics/data.md>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [copy](<https://devfeed.tech/tags/copy.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [destructuring](<https://devfeed.tech/tags/destructuring.md>), [destructuring-assignment](<https://devfeed.tech/tags/destructuring-assignment.md>), [equals](<https://devfeed.tech/tags/equals.md>), [hashcode](<https://devfeed.tech/tags/hashcode.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [learn-to-program](<https://devfeed.tech/tags/learn-to-program.md>), [object](<https://devfeed.tech/tags/object.md>), [open](<https://devfeed.tech/tags/open.md>), [operator](<https://devfeed.tech/tags/operator.md>), [override](<https://devfeed.tech/tags/override.md>), [programming](<https://devfeed.tech/tags/programming.md>), [properties](<https://devfeed.tech/tags/properties.md>), [tostring](<https://devfeed.tech/tags/tostring.md>)

### AI overview

A Kotlin tutorial introducing data classes and destructuring. It explains how data classes relate to equals(), hashCode(), and toString(), beginning with reference equality and overriding inherited functions.

### Source excerpt

At the end of the last chapter, we saw how all objects in Kotlin inherit three functions from an open class called Any. Those functions are equals(), hashCode(), and toString(). In this chapter, we're going to learn about data classes, which are super-powered classes that are especially helpful when we've got an immutable class that mainly just holds properties. To better understand data classes, let's first explore each of the three functions above, and see what's involved when we override them!

## Bundling Data for Android Components with Bundle

DevFeed: [Bundling Data for Android Components with Bundle](<https://devfeed.tech/articles/bundling-things-nice-and-pretty-26169.md>)

Original publisher: [Read original article](<https://zarah.dev/2023/08/21/bundle-parcel.html>)

Author: Zarah Dominguez

Published: 2023-08-21T00:00:00Z

Content type: tutorial

Language: en

Sources: [Zarah Dominguez](<https://devfeed.tech/sources/zarah-dominguez.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Code](<https://devfeed.tech/topics/code.md>), [implementation](<https://devfeed.tech/topics/implementation.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [code](<https://devfeed.tech/tags/code.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [parcelize](<https://devfeed.tech/tags/parcelize.md>)

### AI overview

This Android development tutorial explains how to pass multiple values between components using Bundle. It compares passing values individually with grouping them in data classes and discusses using generated implementation to reduce required boilerplate.

### Source excerpt

Of all the projects that I have worked on over the years, one thing they all have in common is the need to pass things around. Whether passing stuff to an Activity as Intent extras, a Fragment as arguments or its onSaveInstanceState, or even a ViewModel's SavedStateHandle, the most common way to do it is through a Bundle.

## Building a Note-Taking App in Compose

DevFeed: [Building a Note-Taking App in Compose](<https://devfeed.tech/articles/building-a-note-taking-app-in-compose-20024.md>)

Original publisher: [Read original article](<https://technology.doximity.com/articles/building-a-note-taking-app-in-compose>)

Author: Doximity

Published: 2023-07-05T19:47:00Z

Content type: tutorial

Language: en

Sources: [Doximity](<https://devfeed.tech/sources/doximity.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [App](<https://devfeed.tech/topics/app.md>), [Code](<https://devfeed.tech/topics/code.md>), [Template](<https://devfeed.tech/topics/template.md>)

Tags: [app](<https://devfeed.tech/tags/app.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [build](<https://devfeed.tech/tags/build.md>), [building](<https://devfeed.tech/tags/building.md>), [class](<https://devfeed.tech/tags/class.md>), [clean-architecture](<https://devfeed.tech/tags/clean-architecture.md>), [code](<https://devfeed.tech/tags/code.md>), [collect](<https://devfeed.tech/tags/collect.md>), [compose](<https://devfeed.tech/tags/compose.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [di](<https://devfeed.tech/tags/di.md>), [extension-function](<https://devfeed.tech/tags/extension-function.md>), [flow](<https://devfeed.tech/tags/flow.md>), [icons](<https://devfeed.tech/tags/icons.md>), [implement](<https://devfeed.tech/tags/implement.md>), [koin](<https://devfeed.tech/tags/koin.md>), [list](<https://devfeed.tech/tags/list.md>), [state](<https://devfeed.tech/tags/state.md>), [state-management](<https://devfeed.tech/tags/state-management.md>), [view](<https://devfeed.tech/tags/view.md>)

### AI overview

A case study showing how to build a note-taking app with Jetpack Compose. It models note state, renders the notes UI, collects note data through a presenter and Clean Architecture use cases, and plans events for adding, editing, checking, and deleting notes.

### Source excerpt

In this case study, we will build a note-taking app that lets the user add, edit and delete notes. It uses Compose for both the view and presentation layers! Note: This is a follow up to Part 1: Simplifying State Management with Compose and assumes the reader is already familiar with Jetpack Compose. The Template I find it useful to start with the model that represents the state of the screen we're building. It will have a list of notes, with each note containing properties for the text and checkbox: data class NotesUiModel(val notes: List<Note>) : UiModel { data class Note(val text: String, val isChecked: Boolean) : UiModel } It'll be the job of the presenter to produce this model. Initially, let's implement a stub to return an empty list of notes (we'll ignore parameters for now): class NotesListPresenter : Presenter<NotesUiModel, Unit> { @Composable override fun present(params: Unit): NotesUiModel { return NotesUiModel(notes = emptyList()) } } Then we can build our view to render the model that's returned by the presenter: @Composable fun NotesScreen() { val presenter: NotesListPresenter = koinInject() // we use koin for DI val uiModel = presenter.present(Unit) Column { TopAppBar(title = { Text("Notes") }) Notes(uiModel) } } } The View The views themselves are pretty self-explanatory if you're already familiar with building UIs in Compose. For the notes, we'll take in a NotesUiModel argument and create a LazyColumn with the notes property. A FAB button is used for adding new notes, although we'll skip the triggering of events and return to this part in a little bit: @Composable private fun Notes(uiModel: NotesUiModel) { Box { LazyColumn { items(uiModel.notes) { note -> Note(note) } } FloatingActionButton(onClick = { /* TODO */ }) { Icon(imageVector = Icons.Rounded.Add) } } } Then we can render each note with a checkbox, text field and delete button: @Composable private fun Note(uiModel: Note) { Row { Checkbox( checked = uiModel.isChecked, onCheckedChange = { /* T

## Leveraging the Snapshot Mutation Policies of Jetpack Compose

DevFeed: [Leveraging the Snapshot Mutation Policies of Jetpack Compose](<https://devfeed.tech/articles/leveraging-the-snapshot-mutation-policies-of-jetpack-compose-25735.md>)

Original publisher: [Read original article](<https://blog.shreyaspatil.dev/leveraging-the-snapshot-mutation-policies-of-jetpack-compose/>)

Author: Shreyas Patil

Published: 2023-01-30T13:30:39Z

Content type: tutorial

Language: en

Sources: [Shreyas Patil's Blog](<https://devfeed.tech/sources/shreyas-patil-s-blog.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [Compose](<https://devfeed.tech/topics/compose.md>), [ui](<https://devfeed.tech/topics/ui.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [compose](<https://devfeed.tech/tags/compose.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [library](<https://devfeed.tech/tags/library.md>), [mutation](<https://devfeed.tech/tags/mutation.md>), [recompose](<https://devfeed.tech/tags/recompose.md>), [recomposition](<https://devfeed.tech/tags/recomposition.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [state](<https://devfeed.tech/tags/state.md>), [state-management](<https://devfeed.tech/tags/state-management.md>), [ui](<https://devfeed.tech/tags/ui.md>)

### AI overview

A tutorial on SnapshotMutationPolicy in Jetpack Compose, explaining how structural, referential, and never-equal policies determine whether state changes trigger UI recomposition.

### Source excerpt

Understand Snapshot Mutation Policies in Jetpack Compose. Learn how to control when and how your UI recomposes based on state changes.

## Practical Compose Slot API example

DevFeed: [Practical Compose Slot API example](<https://devfeed.tech/articles/practical-compose-slot-api-example-22655.md>)

Original publisher: [Read original article](<https://www.valueof.io/blog/compose-slot-api-example-composable-content-lambda>)

Author: James Shvarts

Published: 2022-05-31T12:54:19Z

Content type: tutorial

Language: en

Sources: [Android Blog - Mobile Dev Notes](<https://devfeed.tech/sources/android-blog-mobile-dev-notes.md>)

Topics: [Compose](<https://devfeed.tech/topics/compose.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Android](<https://devfeed.tech/topics/android.md>), [ui](<https://devfeed.tech/topics/ui.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [api](<https://devfeed.tech/tags/api.md>), [code](<https://devfeed.tech/tags/code.md>), [components](<https://devfeed.tech/tags/components.md>), [compose](<https://devfeed.tech/tags/compose.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [lambda](<https://devfeed.tech/tags/lambda.md>), [layout](<https://devfeed.tech/tags/layout.md>), [learn](<https://devfeed.tech/tags/learn.md>), [screen](<https://devfeed.tech/tags/screen.md>), [ui](<https://devfeed.tech/tags/ui.md>)

### AI overview

A practical example of using the Compose Slot API pattern to build configurable Android screen sections with Kotlin composable content lambdas. It models section titles, optional filters, and section-specific content for reuse and flexibility.

### Source excerpt

Learn how to manage screen sections using Slot API pattern in Compose

## Unconfined Enums Adapter for Moshi

DevFeed: [Unconfined Enums Adapter for Moshi](<https://devfeed.tech/articles/unconfined-enums-adapter-for-moshi-25914.md>)

Original publisher: [Read original article](<https://medium.com/@xxfast/unconfined-enums-adapter-for-moshi-5d84542c8bf0?source=rss-43bae76e8f81------2>)

Author: Isuru Rajapakse

Published: 2022-05-11T12:08:49Z

Content type: tutorial

Language: en

Sources: [Stories by Isuru Rajapakse on Medium](<https://devfeed.tech/sources/stories-by-isuru-rajapakse-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [LineageOS](<https://devfeed.tech/topics/lineageos.md>), [API](<https://devfeed.tech/topics/api.md>), [enum](<https://devfeed.tech/topics/enum.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [api](<https://devfeed.tech/tags/api.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [enum](<https://devfeed.tech/tags/enum.md>), [enum-class](<https://devfeed.tech/tags/enum-class.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [moshi](<https://devfeed.tech/tags/moshi.md>), [retrofit](<https://devfeed.tech/tags/retrofit.md>)

### AI overview

This tutorial presents a Kotlin pattern for handling previously unknown enum-like values from REST APIs with Moshi. It explains Moshi enum adapters, the unknown-value fallback, and an interface-based approach that preserves the server's raw value instead of mapping it only to a generic unknown value.

### Source excerpt

If you wonder what an Unconfined Enum is, wonder no more because it is a thing I just made up. Enums by definition are confined, or finite. Therefore "unconfined enum" is really an oxymoron. Nevertheless, say you have this Fruit enum and want to map each value to an Android string resource. Kotlin's enum properties make this convenient enum class Fruit(@StringRes val stringRes: Int) { Apple(R.string.fruit_apple), Oranges(R.string.fruit_orange) } When we want to consume this enum from a Restful API with a Moshi converter, Moshi automatically generates the enum adapter for you, but if you want to customise the behaviour for whatever reason, you can do object FruitsAdapter { @ToJson fun toJson(type: Fruit): String = type.name @FromJson fun fromJson(name: String): Fruit = Fruit.values().first { it.name == name } } Happy days. Everything is working as expected. When things go bananascom.squareup.moshi.JsonDataException: Expected one of [Apple, Oranges] but was Bananas at path $ Good APIs don't break contracts. Not all APIs are good APIs, so some can break contracts. What do we do now? push out an update with added enum value and its string resource? Perhaps we can make use of EnumJsonAdapter's .withUnknownFallBack() enum class Fruit(@StringRes val stringRes: Int) { Apple(R.string.fruit_apple), Oranges(R.string.fruit_orange), Unknown(R.string.fruit_unknown) } Moshi.Builder() .add(KotlinJsonAdapterFactory()) .add(Fruit::class.java, EnumJsonAdapter.create(Fruit::class.java) .withUnknownFallback(Fruit.Unknown)) .build() This certainly stops the app from crashing, but what if we actually want to show the "bananas" that the API sends? you know, as a fail safe so that users wouldn't end up seeing "unknowns". Let's open up the Enums Enums are by definition finite. Enums are final by design. Enums can't be subclassed but they still can inherit interfaces. We will exploit this to create our "unconfined" enum interface Fruit { val name: String data class Unknown(override val name:

## Make sure to update your StateFlow safely in Kotlin!

DevFeed: [Make sure to update your StateFlow safely in Kotlin!](<https://devfeed.tech/articles/make-sure-to-update-your-stateflow-safely-in-kotlin-25522.md>)

Original publisher: [Read original article](<https://patrykkosieradzki.com/make-sure-to-update-your-stateflow-safely-in-kotlin>)

Published: 2021-07-25T00:00:00Z

Content type: tutorial

Language: en

Sources: [Patryk Kosieradzki](<https://devfeed.tech/sources/patryk-kosieradzki.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [kotlin-coroutines](<https://devfeed.tech/topics/kotlin-coroutines.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Android](<https://devfeed.tech/topics/android.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [code](<https://devfeed.tech/tags/code.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [flow](<https://devfeed.tech/tags/flow.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-coroutines](<https://devfeed.tech/tags/kotlin-coroutines.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

### AI overview

This Kotlin tutorial explains how concurrent updates to MutableStateFlow can lose changes when state is copied and emitted manually. It presents the Kotlin Coroutines update, updateAndGet, and getAndUpdate methods, which retry updates using compareAndSet to safely handle concurrent changes.

### Source excerpt

StateFlow is a common choice for storing app state in Android, e.g., view state. But do you know how to use it correctly?

## Random Animating Pie Button

DevFeed: [Random Animating Pie Button](<https://devfeed.tech/articles/random-animating-pie-button-32075.md>)

Original publisher: [Read original article](<https://www.maiatoday.net/p/random-animating-pie-button/>)

Published: 2021-06-16T21:36:11Z

Content type: tutorial

Language: en

Sources: [maiatoday](<https://devfeed.tech/sources/maiatoday.md>)

Topics: [Compose](<https://devfeed.tech/topics/compose.md>), [Canvas](<https://devfeed.tech/topics/canvas.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [animate](<https://devfeed.tech/tags/animate.md>), [canvas](<https://devfeed.tech/tags/canvas.md>), [code](<https://devfeed.tech/tags/code.md>), [color](<https://devfeed.tech/tags/color.md>), [component](<https://devfeed.tech/tags/component.md>), [compose](<https://devfeed.tech/tags/compose.md>), [custom](<https://devfeed.tech/tags/custom.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [exploring](<https://devfeed.tech/tags/exploring.md>), [fun](<https://devfeed.tech/tags/fun.md>), [functions](<https://devfeed.tech/tags/functions.md>), [jetpack](<https://devfeed.tech/tags/jetpack.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [random](<https://devfeed.tech/tags/random.md>), [val](<https://devfeed.tech/tags/val.md>), [var](<https://devfeed.tech/tags/var.md>)

### AI overview

A Jetpack Compose sample demonstrates a custom pie-chart component that draws with Canvas and animates to a random percentage when a button is clicked.

### Source excerpt

I am exploring animations with small sampler functions using Jetpack Compose. This one is a custom component that draws a little pie chart. It will animate a random pie value on the click of the button. data class PieData( val foreground: Color = Color.White, val strokeWidth: Dp = 4.dp, val percentage: Float ) @Composable fun PieStatus( modifier: Modifier = Modifier, pieData: PieData ) { var animationPlayed by remember { mutableStateOf(false) } val currentPercentage = animateFloatAsState( targetValue = if (animationPlayed) pieData.percentage else 0f, animationSpec = tween(1000) ) LaunchedEffect(key1 = true) { animationPlayed = true } Canvas( modifier = modifier ) { val canvasWidth = size.width val canvasHeight = size.height drawCircle( color = pieData.foreground, center = Offset(x = canvasWidth / 2, y = canvasHeight / 2), radius = canvasWidth / 2 - pieData.strokeWidth.toPx(), style = Stroke(width = pieData.strokeWidth.toPx()) ) val arcPadding = pieData.strokeWidth.toPx() * 2 drawArc( color = pieData.foreground, startAngle = -90f, sweepAngle = currentPercentage.value * 360, useCenter = true, topLeft = Offset(arcPadding, arcPadding), size = Size(size.width - (arcPadding * 2f), size.height - (arcPadding * 2f)) ) } } code

## Modelling UI State on Android

DevFeed: [Modelling UI State on Android](<https://devfeed.tech/articles/modelling-ui-state-on-android-25873.md>)

Original publisher: [Read original article](<http://lordraydenmk.github.io//2021/modelling-ui-state/>)

Author: Stojan Anastasov

Published: 2021-01-29T00:00:00Z

Content type: tutorial

Language: en

Sources: [Stojan Anastasov's blog](<https://devfeed.tech/sources/stojan-anastasov-s-blog.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [android-development](<https://devfeed.tech/topics/android-development.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-development](<https://devfeed.tech/tags/android-development.md>), [cardinality](<https://devfeed.tech/tags/cardinality.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [data-structure](<https://devfeed.tech/tags/data-structure.md>), [fp](<https://devfeed.tech/tags/fp.md>), [functional](<https://devfeed.tech/tags/functional.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [livedata](<https://devfeed.tech/tags/livedata.md>), [rxjava](<https://devfeed.tech/tags/rxjava.md>), [sealed-class](<https://devfeed.tech/tags/sealed-class.md>), [stateflow](<https://devfeed.tech/tags/stateflow.md>), [types](<https://devfeed.tech/tags/types.md>), [ui](<https://devfeed.tech/tags/ui.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

### AI overview

This article explains how to model Android UI state in Kotlin using data classes and sealed classes. It connects types with sets and cardinality, then describes product types and sum types as tools for representing valid application states.

### Source excerpt

The recommended approach from Google for Android development is holding the UI state in a ViewModel and having the View observe it. To achieve that one can use LiveData, StateFlow, RxJava or a similar tool. But how to model the UI state? Use a data class or a sealed class? Use one observable property or many? I will describe the tradeoffs between the approaches and present a tool to help you decide which one to use. This article is heavily inspired by Types as Sets from the Elm guide, a large part is a translation from Elm to Kotlin. Photo by Marc-Olivier Jodoin on Unsplash Types as sets By Making Data Structure we can make sure the possible values in code exactly match the valid values in real life. Doing that helps to avoid a whole class of bugs related to invalid data. To achieve that, first we need to understand the relationship between Types and Sets. We can think of Types as sets of values, they contain unique elements and there is no ordering between them. For example: Nothing - the empty set, it contains no elements Unit - the singleton set, it contains one element - Unit Boolean - contains the elements true and false Int - contains the elements: ... -2, -1, 0, 1, 2 ... Float - contains the elements: 0.1, 0.01, 1.0 .... String - contains the elements: "", "a", "b", "Kotlin", "Android", "Hello world!"... So when you write: val x: Boolean it means x belongs to the set of Boolean values and can be either true or false. Cardinality In Mathematics, Cardinality is the measure of "number of elements" of a Set. For example the set of Boolean contains the elements [true, false] so it has a cardinality = 2. Let's take a look at the cardinality of the sets mentioned above: Nothing - 0 Unit - 1 Boolean - 2 Short - 65535 Int - ∞ Float - ∞ String- ∞ Note: The cardinality of Int and Float is not exactly infinity, it's 2^32 however that is a huge number. When building apps, we use built-in types and create custom types using constructs like data classes and sealed classes. Product

## Expandable lists in Jetpack Compose

DevFeed: [Expandable lists in Jetpack Compose](<https://devfeed.tech/articles/expandable-lists-in-jetpack-compose-25896.md>)

Original publisher: [Read original article](<https://proandroiddev.com/expandable-lists-in-jetpack-compose-b0b78c767b4?source=rss-56174fa84bcc------2>)

Author: Denys Rudenko

Published: 2021-01-11T18:21:04Z

Content type: tutorial

Language: en

Sources: [Stories by Denis Rudenko on Medium](<https://devfeed.tech/sources/stories-by-denis-rudenko-on-medium.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [ui](<https://devfeed.tech/topics/ui.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [compose](<https://devfeed.tech/tags/compose.md>), [constraintlayout](<https://devfeed.tech/tags/constraintlayout.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [expandable-animation](<https://devfeed.tech/tags/expandable-animation.md>), [expandable-list](<https://devfeed.tech/tags/expandable-list.md>), [expandable-view](<https://devfeed.tech/tags/expandable-view.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [layout](<https://devfeed.tech/tags/layout.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [memory](<https://devfeed.tech/tags/memory.md>), [state](<https://devfeed.tech/tags/state.md>), [stateflow](<https://devfeed.tech/tags/stateflow.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

### AI overview

A tutorial explains how to build expandable lists in Jetpack Compose. It uses a card data class, a view model with StateFlow for cards and expanded card IDs, composable functions that observe state, and transition state to animate card expansion.

### Source excerpt

Expandable views are a common way to hide details of a visualised data structures. Let's take a look at how the following can be achieved in 6 steps, using compose: https://medium.com/media/b9dface7145a04eb3bee8ac03eed3a4e/hrefStep 1: Creating a data class for carddata class ExpandableCardModel(val id: Int, val title: String)Step 2: Create a data source We'll be using AAC viewModel example here, but feel free to use any "controller" abstraction you like. https://medium.com/media/61d179f82414c569e4d8e415bbed8aa6/href This class serves 4 purposes: Holds list of cards using MutableStateFlow in _cards field, and exposes a StateFlow to observers via cards field. Holds list of expanded card ids in _expandedCardIdsList, and exposes them to observers via expandedCardIdsList field. Provides list of cards using getFakeData() function. We need a coroutine here, to emit the testList into _cards. Contains a onCardArrowClicked() to mark cards as expanded by adding tapped card id to _expandedCardIdsList, and notify observers about this change by mutating the state of _expandedCardIdsList. Step 3: MainActivityhttps://medium.com/media/6e10348f08fc4004c3a397cd46c19bd0/href We are initialising the CardsViewModel here, and providing it to the CardsScreen composable function. Step 4: CardsScreen composablehttps://medium.com/media/b2cd50c3ab379cd75897eda6b1aca4c6/href We are observing the viewModel.cards containing our list of cards, and viewModel.expandedCardIds with the help of .collectAsState(). What's the purpose of .collectAsState()? It's converting StateFlow into a State. Update: using .collectAsStateWithLifecycle() which is the same thing, but lifecycle aware, and helps to reduce memory consumption when UI is not visible to the user. More info in this article. What's a State? From the documentation: " State is a value holder where reads to the value property during the execution of a composable function, the current recomposeScope will be subscribed to changes of that value." Step

## Designing and Working with Single View States on Android

DevFeed: [Designing and Working with Single View States on Android](<https://devfeed.tech/articles/designing-and-working-with-single-view-states-on-android-27060.md>)

Original publisher: [Read original article](<https://zsmb.co/designing-and-working-with-single-view-states-on-android/>)

Author: Márton Braun

Published: 2020-05-25T17:00:00Z

Content type: tutorial

Language: en

Sources: [zsmb.co](<https://devfeed.tech/sources/zsmb-co.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [App](<https://devfeed.tech/topics/app.md>), [ui](<https://devfeed.tech/topics/ui.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [marton-braun](<https://devfeed.tech/tags/marton-braun.md>), [mvi](<https://devfeed.tech/tags/mvi.md>), [mvvm](<https://devfeed.tech/tags/mvvm.md>), [network](<https://devfeed.tech/tags/network.md>), [sealed-classes](<https://devfeed.tech/tags/sealed-classes.md>), [state](<https://devfeed.tech/tags/state.md>), [zsmb](<https://devfeed.tech/tags/zsmb.md>), [zsmb-co](<https://devfeed.tech/tags/zsmb-co.md>), [zsmb13](<https://devfeed.tech/tags/zsmb13.md>), [zsmbco](<https://devfeed.tech/tags/zsmbco.md>)

### AI overview

This tutorial explains how to represent Android screen state with a single ViewState object. It compares a single data class with a hierarchy of sealed classes, emphasizing how sealed classes can better model mutually exclusive states such as loading, content, and error.

### Source excerpt

Describing the state of a screen is a common practice these days thanks to MVI popularizing the concept. Let's take a look at some examples of how you can design your state objects neatly using data classes and sealed classes, and how you can put them into practice.

## Data classes aren't (that) magical

DevFeed: [Data classes aren't (that) magical](<https://devfeed.tech/articles/data-classes-aren-t-that-magical-27059.md>)

Original publisher: [Read original article](<https://zsmb.co/data-classes-arent-that-magical/>)

Author: Márton Braun

Published: 2019-01-16T16:00:00Z

Content type: tutorial

Language: en

Sources: [zsmb.co](<https://devfeed.tech/sources/zsmb-co.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Code](<https://devfeed.tech/topics/code.md>), [Java](<https://devfeed.tech/topics/java.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [classes](<https://devfeed.tech/tags/classes.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [create](<https://devfeed.tech/tags/create.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [destructuring](<https://devfeed.tech/tags/destructuring.md>), [generate](<https://devfeed.tech/tags/generate.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [marton-braun](<https://devfeed.tech/tags/marton-braun.md>), [optional](<https://devfeed.tech/tags/optional.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [properties](<https://devfeed.tech/tags/properties.md>), [zsmb](<https://devfeed.tech/tags/zsmb.md>), [zsmb-co](<https://devfeed.tech/tags/zsmb-co.md>), [zsmb13](<https://devfeed.tech/tags/zsmb13.md>), [zsmbco](<https://devfeed.tech/tags/zsmbco.md>)

### AI overview

This tutorial explains what Kotlin data classes add to regular classes. It covers generated methods, how primary-constructor properties affect those methods, destructuring support, and the copy method with optional named parameters.

### Source excerpt

Data classes are great, but don't underestimate what a regular Kotlin class can do on its own.

## Note to Future Me -- Testing Intents with Matchers

DevFeed: [Note to Future Me -- Testing Intents with Matchers](<https://devfeed.tech/articles/note-to-future-me-testing-intents-with-matchers-32073.md>)

Original publisher: [Read original article](<https://www.maiatoday.net/p/note-to-future-me-testing-intents-with-matchers/>)

Published: 2018-01-26T14:54:45Z

Content type: tutorial

Language: en

Sources: [maiatoday](<https://devfeed.tech/sources/maiatoday.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [test](<https://devfeed.tech/topics/test.md>), [parcelable](<https://devfeed.tech/topics/parcelable.md>), [Code](<https://devfeed.tech/topics/code.md>), [Library](<https://devfeed.tech/topics/library.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [data](<https://devfeed.tech/tags/data.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [error-messages](<https://devfeed.tech/tags/error-messages.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [library](<https://devfeed.tech/tags/library.md>), [parcelable](<https://devfeed.tech/tags/parcelable.md>), [testing](<https://devfeed.tech/tags/testing.md>), [testing-matchers](<https://devfeed.tech/tags/testing-matchers.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

This tutorial demonstrates testing Android activity intents with Espresso and Hamcrest matchers in Kotlin. It passes a parcelable data object between activities, verifies the intent extra and its properties, and shows how custom matchers can improve error messages and test only selected properties.

### Source excerpt

I want to make my little experiments public and save them as a reminder for future me. So here is yet another post on Matchers and Espresso testing. I want to test this: First activity starts another activity at a button click. First activity passes a parcelable object to the second activity. Test that the intent that starts the second activity contains the object with the correct properties. I built a contrived example, MainActivity collects some info and passes this to StarActivity in a parcelable called ContrivedParams. See the sample code on GitHub. To write the tests I brushed up on Hamcrest[1][2][3]: a library that makes it easier to write readable tests. Instead of assert(expected==actual) you can write almost-english assertThat(actual, is(expected)) which is a sugar coated version of assertThat(actual is(equalto(expected))) Sadly though is is a hard keyword in Kotlin so I ended up using the isA() and equalTo() varieties of calls rather than escaping is with backticks. Another reason to use Hamcrest -- better error messages. Compare these two messages. java.lang.AssertionError at net.maiatoday.hellointentmatcher.ContrivedParamsTest.showErroMessagesTest(ContrivedParamsTest.kt:37) with the message given by a custom matcher java.lang.AssertionError: Expected: title should return "Hello World" but: was "Hello World!" at net.maiatoday.hellointentmatcher.ContrivedParamsTest.showErroMessagesTest(ContrivedParamsTest.kt:42) or the error message given by an object matcher java.lang.AssertionError: Expected: <ContrivedParams(title=Hello World, starCount=3, colour=#00b0ff)> but: was <ContrivedParams(title=Hello World!, starCount=4, colour=#00b0fff)> at net.maiatoday.hellointentmatcher.ContrivedParamsTest.showErroMessagesTest(ContrivedParamsTest.kt:47) The parameters for the second activity is passed in a parcelable data class. I used the Espresso-intents library . Start the activity with an IntentsTestRule. The IntentsTestRule initialises the Espresso intents before each

## Writing a RecyclerView Adapter in Kotlin (KAD 16)

DevFeed: [Writing a RecyclerView Adapter in Kotlin (KAD 16)](<https://devfeed.tech/articles/writing-a-recyclerview-adapter-in-kotlin-kad-16-27219.md>)

Original publisher: [Read original article](<https://antonioleiva.com/recyclerview-adapter-kotlin>)

Published: 2017-03-14T00:00:00Z

Content type: tutorial

Language: en

Sources: [Antonio Leiva](<https://devfeed.tech/sources/antonio-leiva.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [recyclerview](<https://devfeed.tech/topics/recyclerview.md>), [Android](<https://devfeed.tech/topics/android.md>), [implementation](<https://devfeed.tech/topics/implementation.md>), [Code](<https://devfeed.tech/topics/code.md>), [data](<https://devfeed.tech/topics/data.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [extension-function](<https://devfeed.tech/tags/extension-function.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-android](<https://devfeed.tech/tags/kotlin-android.md>), [recyclerview](<https://devfeed.tech/tags/recyclerview.md>), [viewholder](<https://devfeed.tech/tags/viewholder.md>)

### AI overview

This tutorial explains how to create a simple, immutable RecyclerView Adapter in Kotlin for an Android app. It covers the model, adapter structure and constructor, method implementations, view inflation, and a ViewHolder that maps model values and click listeners to views.

### Source excerpt

Everything Android, Kotlin and other random topics

## Kotlin Data Classes Reduce Boilerplate Code

DevFeed: [Kotlin Data Classes Reduce Boilerplate Code](<https://devfeed.tech/articles/data-classes-in-kotlin-save-a-good-bunch-of-lines-of-code-kad-10-27155.md>)

Original publisher: [Read original article](<https://antonioleiva.com/data-classes-kotlin>)

Published: 2017-01-25T00:00:00Z

Content type: tutorial

Language: en

Sources: [Antonio Leiva](<https://devfeed.tech/sources/antonio-leiva.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Boilerplate](<https://devfeed.tech/topics/boilerplate.md>), [Code](<https://devfeed.tech/topics/code.md>), [Java](<https://devfeed.tech/topics/java.md>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [code](<https://devfeed.tech/tags/code.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [copy](<https://devfeed.tech/tags/copy.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [destructuring](<https://devfeed.tech/tags/destructuring.md>), [function](<https://devfeed.tech/tags/function.md>), [generate](<https://devfeed.tech/tags/generate.md>), [immutability](<https://devfeed.tech/tags/immutability.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [properties](<https://devfeed.tech/tags/properties.md>)

### AI overview

This tutorial explains Kotlin data classes, which represent state and automatically provide useful generated code. It covers destructuring, immutable-object copying, and how data classes reduce boilerplate compared with Java.

### Source excerpt

Everything Android, Kotlin and other random topics