Questions tagged [sealed-class]
142 questions
0
votes
1 answer
how to use freezed on a class with custome function that inherits from a non-sealed class in dart?
I have just started learning freezed. I have a GameBase class below:
import 'package:json_annotation/json_annotation.dart';
part 'game_base.g.dart';
@JsonSerializable()
class GameBase {
final int id;
final String facilityName;
final…

Kimiya Zargari
- 324
- 1
- 14
0
votes
1 answer
How to get copy of the ArrayList in android using kotlin
How to get the copy of arraylist of sealed class in android
private var homePageApiResponseList : ArrayList = ArrayList()
Here HomeApiResponseModel is a Sealed class. HomeApiResponseModel is given as Below
sealed class…

Suman Radhakrishnan
- 438
- 8
- 16
0
votes
1 answer
Type mismatch. Required: Result! Found: Result>?
I am developing android app and I have implemented success and failure cases in viemodel class but I am getting following mismatch Type mismatch.
Required:
Result!
Found:
Result
below my NewsViewModel where I have implemented success and…

Yodgorbek Komilov
- 193
- 1
- 2
- 11
0
votes
0 answers
Proper way of handle sealed class property in kotlin
Hey I am working in Android Kotlin. I am learning this LatestNewsUiState sealed class example from Android doc. I made my own sealed class example. But I am confused little bit, how can I achieved this. Is I am doing right for my scenario or…

Kotlin Learner
- 3,995
- 6
- 47
- 127
0
votes
1 answer
replace enums with multiple extends sealed classes
Currently I have three enum classes that represents states in my state machine and one to display operations
interface State
enum class OperationState : State {
InProgress,
Finished,
Error
}
enum class FirstState : State {
//some…

J.Doe
- 153
- 1
- 2
- 10
0
votes
1 answer
Assigning abstract val a value in sealed class
I've a sealed class from which a couple of abstract classes inherit from. Since there are a bunch of fields in sealed class that need to be initialized in abstract class, I'm trying to move it to the secondary constructor however secondary…

user2498079
- 2,872
- 8
- 32
- 60
0
votes
0 answers
How can we create non-extendable classes in the dart
In Java we know to create sealed class. If we use final with class no one can extend this class. In Dart there is no any option. we can extend every class. If we extend every class so how we cannot extend Dart built in classes?

Aarij Amir
- 11
0
votes
3 answers
Sealed classes generics
I have this scenario where I have a super abstract class that emits different types of events using Kotlin sealed classes.
These events are modeled as follows.
sealed class BaseEvent {
object ConnectionStarted : BaseEvent()
object…

Hamza Sharaf
- 811
- 9
- 25
0
votes
1 answer
Map Retrofit RxJava Result into sealed class Success and failure
I am using retrofit with RXJava to call my APIs, i am trying to map my call result into sealed class success and failure parts,
I did the mapping part but I am always getting this error java.lang.RuntimeException: Failed to invoke private Result()…

Omar Hassan
- 727
- 1
- 11
- 24
0
votes
2 answers
Type mismatch. Required: Result>! Found: Success
I am have implemented sealed classes if I get response correctly I will get Result.Success if the error Resuilt.Error
below my ViewModel where I have implemented that logic
@HiltViewModel
class GiphyTaskViewModel
@Inject
constructor(private val…
user16305099
0
votes
3 answers
Is it possible to compose two sealed classes?
Image that I have two distinct Kotlin sealed classes.
sealed class Fruit {
object Apple : Fruit()
object Orange : Fruit()
object Banana : Fruit()
}
sealed class Vegetables {
object Broccoli : Vegetable()
object Carrot : Vegetable()
…

Jaxsun
- 526
- 6
- 11
0
votes
1 answer
Check through all subclasses of a sealed class in Kotlin
I have a sealed class containing balls as objects, for a pool game. Elsewhere in the code I am using BallType, which is an enum clas. I would like to be able to get the ball object when needed by providing the ball type. Is there a way to do…

Victor Cocuz
- 96
- 1
- 10
0
votes
1 answer
MockK verifySequence not working because of object reference
It is common for me to work with a state class (a sealed class) that I use to control the state of my screen (let's say Success, Error and Loading). So I'd have something like:
sealed class State {
object Loading: State()
object Success :…

Leonardo Sibela
- 1,613
- 1
- 18
- 39
0
votes
2 answers
Extend data class sealed class kotlin
I have a sealed class that has different subtypes extending from it. When I try to use a when clause to filter out a subtype I keep getting unresolved reference "name"
sealed class Fruit(val name: String) {
object APPLE : Fruit(“apple”)
…

luckysing_noobster
- 1,933
- 5
- 24
- 50
0
votes
1 answer
Coroutines with sealed class
My project has a lot of operations that must be performed one after another. I was using listeners, but I found this tutorial Kotlin coroutines on Android and I wanted to change my sever call with better readable code. But I think I am missing…

KeitL
- 188
- 2
- 13