data-class Questions

11

Solved

Suppose I only want one or two fields to be included in the generated equals and hashCode implementations (or perhaps exclude one or more fields). For a simple class, e.g.: data class Person(val id...
Topminnow asked 12/4, 2015 at 22:18

3

Solved

After knowing Kotlin, love the data class. I could replace Java classes that has equal and hash and toString to it. Most of these Java classes are serializable class. So my question is, when we con...
Sarinasarine asked 16/4, 2020 at 1:15

15

Solved

Data classes seem to be the replacement to the old-fashioned POJOs in Java. It is quite expectable that these classes would allow for inheritance, but I can see no convenient way to extend a data c...
Superannuate asked 18/10, 2014 at 20:18

2

Solved

The following will work, but I'd rather not need to repeat the __hash__ in each subclass. Is there a way to tell the dataclass to inherit the hash function (i.e. not set it to None)? from dataclas...
Theodosia asked 31/12, 2018 at 18:14

2

I am trying to create a small app using Kotlin Multiplatform where i can save book titles and their authors but i'm struggling with the data classes and how to map them together so that i get the a...
Scheller asked 31/3, 2022 at 14:8

5

Solved

Assume I have a data class: data class SensorData(val name: String, val temp : Double) I create this SensorData object from either an REST service or by internal setter method, whereas name is a...
Master asked 23/5, 2019 at 8:47

3

Solved

Is it possible to call the copy() function of a data class via reflection in Kotlin? How can I get a reference to the function itself? Is there a superclass for all data classes?
Foetation asked 27/3, 2018 at 10:57

12

Solved

Could someone explain how exactly the copy method for Kotlin data classes work? It seems like for some members, a (deep) copy is not actually created and the references are still to the original. ...
Williford asked 17/11, 2017 at 21:23

2

Solved

I have created a data class data class Something ( val a : String, val b : Object, val c : String ) as later in my program, I need the string representation of this data class I tried to extend...
Shimberg asked 13/3, 2016 at 13:41

3

Solved

I know a lot of similar questions here in StackOverflow, but nothing solved mine. I have a generic data class: data class ServiceCall<out T>(val result: T?, val exception: String?, val pag...
Lightner asked 25/9, 2017 at 8:48

4

Solved

I'm making a dictionary-like app with Kotlin in which I have a data class for every word and their meaning + declensions, so I have a data class with about 20 parameters: data class Word( val para...
Dress asked 9/10, 2022 at 15:37

5

Solved

I want to have a data class accepting a read-only list: data class Notebook(val notes: List<String>) { } But it can accept MutableList as well, because it is a subtype of the List. For ex...
Trigon asked 8/6, 2017 at 12:9

3

Solved

I'm a beginner of Kotlin, I have read some sample code about data class, it seems that the parameter are all val type just like Code A I need to change some values of data class MSetting, so I des...
Gangue asked 6/4, 2018 at 8:31

2

Solved

I have several data classes which include a var id: Int? field. I want to express this in an interface or superclass, and have data classes extending that and setting this id when they are construc...
Clearness asked 17/7, 2017 at 16:44

5

Solved

I have the following data class data class PuzzleBoard(val board: IntArray) { val dimension by lazy { Math.sqrt(board.size.toDouble()).toInt() } } I read that data classes in Kotlin get equals()/...
Siler asked 30/5, 2016 at 11:21

1

I have a kotlin data class with default values and when I try to map it using MapStruct it throws an error at runtime because it will try to assign a null value to a non-nullable type for a propert...
Willin asked 15/3, 2022 at 15:28

2

I am able to find method for exporting Java's list of POJO to csv but unable to find a method to export Kotlin's list of data class to CSV.
Leggett asked 24/2, 2019 at 11:58

3

Solved

As I am converting my java project to kotlin project, I came to know about data classes in kotlin(replacement of Java model classes). Now I have a requirement for my kotlin data class to support ...
Samson asked 15/6, 2019 at 6:26

1

Solved

In Jetpack Compose we see all built in composable have flattened inputs, is it intended? Or wrapping too many inputs with data class (which is good and clean practice) has the same performance? Con...
Clemenceau asked 17/2, 2022 at 10:49

4

Solved

In my project I use AutoValue for my old model classes. I started using Kotlin and I want to use Data Classes instead of AutoValue. I want to disable the obfuscation for all Data classes in my Data...
Shana asked 7/9, 2017 at 14:16

1

Solved

I have data class data class Author( val id: String, val name: String, val books: MutableList<Book> = mutableListOf() ) {} And I wrote request using jooq val resultSet = dsl.select(author...
Suppletory asked 10/6, 2021 at 23:12

3

Solved

Hi I have a Kotlin data class as follows data class User ( @get:Exclude val gUser: Boolean, @get:Exclude val uid: String, @get:PropertyName("display_name") val displayName: String, @get:Proper...
Dorelle asked 6/6, 2018 at 14:34

3

Solved

I have a sealed class like so: sealed class SealedClass { object Object1 : SealedClass() object Object2 : SealedClass() object Object3 : SealedClass() data class DataClass(val sealedClass: ...
Tetanic asked 8/8, 2019 at 2:57

1

Solved

Java 14 offers a new feature called records, helping to create JavaBeans. What is the difference between Kotlin's data classes and Java records?
Byran asked 21/10, 2020 at 16:55

4

Solved

The following does not work, but hopefully helps you understand what I mean: class Example<T : DataClass> In case you would like to know what I am trying to accomplish, this is an example ...
Subedit asked 5/6, 2016 at 16:22

© 2022 - 2025 — McMap. All rights reserved.