Questions tagged [sealed-class]

142 questions
0
votes
1 answer

Unnecessary/broken check for abstract intermediary subclass of sealed class required in exhaustive when

I have a sealed class hierarchy like so: sealed class Base class A : Base() abstract class B : Base() class C : Base() class D : Base() Then I want to have an exhaustive when: fun main() { val c: Base = C() when (c) { is A…
Yona Appletree
  • 8,801
  • 6
  • 35
  • 52
0
votes
1 answer

Moshi error: @JsonClass can't be applied to [class]. must not be sealed

Imagine this data sample "meta_data": [ { "id": 40097, "key": "_wcf_frm_created", "value": "" }, { "id": 40098, …
0
votes
1 answer

Kotlin enum type where child is interchangeable with parent

I have a class Transaction with subclasses Income and Expense which have a property category. Incomes and expenses have distinct categories, i.e. an IncomeCategory and ExpenseCategory. I need a list of both incomes and expenses, so I create a list…
0
votes
1 answer

How to set unique id for sealed class for ItemCallback?

I implemented ListAdapter, that T is sealed class ViewHolderModel. Then, I trying to implement DiffUtil.ItemCallback to be used Adapter, but I faced a problem. ViewHolderModel included various data objects, they are unique id of some objects are…
Ethan Choi
  • 2,339
  • 18
  • 28
0
votes
2 answers

Firebase: How to check if document write was successful

I want to check if my database write was successful in order to show the user an error message. My current approach doesn't work as it says "Type mismatch, required Unit found EmailStatus" Current approach class EmailRepositoryImpl : EmailRepository…
Andrew
  • 4,264
  • 1
  • 21
  • 65
0
votes
0 answers

Do I need a nested Sealed class?

Need help with my example sealed class sealed class Color object Red: Color() object Green: Color() object Blue: Color() class NewColor( var flag: Boolean = false, var id: String = "" or Int = -1 <-----I want id to be either an Int or…
Android
  • 119
  • 9
0
votes
1 answer

Handle api response using sealed class in rxjava

I want to handle api response using sealed class sealed class Result { data class Success(val value: T) : Result() data class Failure(val throwable: Throwable) : Result() } My api is working properly…
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
0
votes
1 answer

How sealed class modifier helps with pattern matching in Java?

Latest Java release 15 offers new functionality - sealed modifier. I went through the JEP and it says: Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them. Goals: Allow the author of a class or…
Serhii Povísenko
  • 3,352
  • 1
  • 30
  • 48
0
votes
1 answer

what is the reason for prevent inherit from string class in c#?

i read some articles but most of them are abstracted and i can't get answering of my questions. i know the difference between Abstract and Sealed Classes.but when my instructor explained the difference he said in c# when you want to make some…
Muhamed Taha
  • 15
  • 1
  • 8
0
votes
1 answer

Not able to use readObject() using ObjectInputStream and SealedObject in java. Getting runtime error

Getting run time error as below: Exception in thread "main" java.lang.ClassCastException: class Message cannot be cast to class javax.crypto.SealedObject (Message is in unnamed module of loader 'app'; javax.crypto.SealedObject is in module java.base…
0
votes
1 answer

About sealed subclass of a sealed class in Kotlin

the code below compiles while it is impossible to go through conditions Color.Dark and Color.Light as these two classes are abstract. Did I miss something ? sealed class Color () { sealed class Dark () { class DarkRed : Color() class…
Emile Achadde
  • 1,715
  • 3
  • 10
  • 22
0
votes
2 answers

Practical example of sealed classes in Android Development

I'm newbie of Kotlin. I'm learning sealed classes and I don't understand how could I use it in Android development. Can you give me an example?
omega1100100
  • 39
  • 1
  • 6
0
votes
1 answer

Kotlin: functional programming, sealed class List

I am practicing some functional programming with a sealed class List and a map function. So far the code for the sealed class sealed class List { class Node ( val head : T , val tail : List) : List () { override fun…
Momo
  • 73
  • 6
0
votes
2 answers

Force all Kotlin Sealed classes to have a standard entry?

I am investigating Kotlin Sealed Classes. I wish to force all my Sealed classes to have a standard value of NO_OP. for example:- Sealed Class 1 sealed class Operation { object NO_OP: Operation() class Add(val value: Int) : Operation() …
Hector
  • 4,016
  • 21
  • 112
  • 211
0
votes
1 answer

KotlinX serialization - Polymorphic content using sealed

Let's assume I have following json objects : { "type": "video", "...": "..." } { "type": "image", "...": "..." } They both represent media object. Kotlin sealed model looks like : sealed class Media { …
Nicolas Duponchel
  • 1,219
  • 10
  • 17
1 2 3
9
10