Questions tagged [sealed-class]
142 questions
0
votes
1 answer
Proguard rules for Sealed classes
I have a sealed class as below.
sealed class Fruits(private val category: String) {
object Apple : Fruits("APPLE")
class Banana : Fruits("BANANA)
}
It gets obfuscated when minifyEnabled is true and debuggable is enabled like…

Navinpd
- 772
- 7
- 15
0
votes
0 answers
How should I use `sealed class` or `hashmap` or `enums` in a specific case?
I use sealed classes to distinguish normal functions from suspend functions.
sealed class Function {
class SuspendFunction(val execute: suspend () -> Boolean) : Function() {
suspend operator fun invoke() {
execute()
}
}
class…

SageJustus
- 631
- 3
- 9
0
votes
0 answers
Failed to invoke private [packagename].LiveExamResponse() with no args"
I get 2 data class responses, one at a time, from the network call. I used a sealed class for that but got a response error on the sealed class mentioning, "Failed to invoke private [packagename].LiveExamResponse() with no args"
on logcat I'm…

Sijan Neupane
- 116
- 2
- 8
0
votes
2 answers
How to mock functions returning a sealed class in Mockk?
When stubbing a function returning a sealed class with Mockk as following
File BoeTest.kt
package nl.dstibbe.example
import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.Test
sealed class MySeal
data class MyOtherSeal(val…

dstibbe
- 1,589
- 18
- 33
0
votes
1 answer
kotlin declaring Object within sealed class and initialized
sealed class StockLabel : Label() {
object OutOfStockLabel : StockLabel()
}
I know sealed class in kotlin is implicitly abstract and we will get compile error if doing so. But I saw the usage of the code above, the 'OutOfStockLabel' is declared…

user13902742
- 505
- 1
- 4
- 6
0
votes
0 answers
Scala 2.13 - Use ADT to extend a sealed trait scala
I have seen some examples to use ADT to extend data types to fit into either of the options but I am little confused on how to implement it in this kind of use case. In case classes I would create them and just add extends TraitName but what about…

Shivam Sahil
- 4,055
- 3
- 31
- 62
0
votes
0 answers
@RequestBody with Sealed Interface: how to de-serialize
I am doing a basic Login flow, where I expect my LoginRequest DTO to be one of three possible types, as described in the code snippet below. But I am having trouble using this in a @RequestBody because spring doesn't understand how to de-serialize…

Somjit
- 2,503
- 5
- 33
- 60
0
votes
1 answer
How to get a message sent from View Model using a sealed class?
I have an app that uses Kotlin with an MVVM approach. My goal here is to send the state (SUCCESS, FAIL, ERROR, EXCEPTION.VM_INSERT...) from View Model to activity. In my activity, I observe the state and based on that I will inform the user about…

DevPeter
- 83
- 2
- 8
0
votes
0 answers
This sealed class for handling retrofit response is not working
I'm trying to create a Wrapper class for handling the api call in retrofit
Wrapper sealed class
sealed class NetworkResult {
class Success(val data: T) : NetworkResult()
class Error(val code: Int, val message:…

newbie_coder
- 225
- 2
- 9
0
votes
3 answers
Strings and sealed clases
I need to obtain some string that match with another. For example, when my string is “Ne” I need to obtain “Neon”.
I made this, but I think that this isn’t the best way. I think that is better use sealed class. Is there some way to match a string…

Electrocode
- 127
- 1
- 8
0
votes
1 answer
What does it mean by: enum constant is a single instance but subclass of a sealed class can have multiple instances?
I am trying to understand:
Kotlin Sealed Class Official Doc
But I am struggling to understand the phrase:
each enum constant exists only as a single instance, whereas a subclass of a sealed class can have multiple instances, each with its own…

Sagar Patel
- 506
- 1
- 8
- 23
0
votes
1 answer
I want to know the definition of "sealed class" in Dart
https://www.youtube.com/watch?v=2Cl0C-9dK48&list=PLjxrf2q8roU1fRV40Ec8200rX6OuQkmnl
Type Promotion | Decoding Flutter
In the above video, there is the following explanation.
Dart doesn't have sealed classes. That means every class can be
extended…

森口万太郎
- 805
- 6
- 20
0
votes
1 answer
RuntimeException: Exception inflating kotlin:navigation/nav_graph
We had a RuntimeException while we put a safeArgs into the navigation graph and this crash didn't give us any more guide to fix it.
In the first impression, we were following this to ensure that those classes were Parcelize or not.
Therefore, those…

Majid Khosravi
- 129
- 2
- 4
0
votes
1 answer
How to use mutable live data of type sealed class with data binding
I am trying to handle visibility of a ProgressBar using mutable LiveData of type sealed class with data binding but getting below error.
cannot find symbol variable sealed class
Below is my code
ViewModel
class RevampSplashViewModel:…

Shahbaz Hashmi
- 2,631
- 2
- 26
- 49
0
votes
1 answer
How do I fetch the overridden member of a sealed trait via reflection?
I'm trying to write a generalised function that takes a Type of SomeSealedClass and uses reflection to return a list of values overridden by the trait's child classes/objects.
sealed abstract class Sealed(val name: String)
object Sealed {
case…

Turbo123
- 35
- 1
- 6