Questions tagged [sealed-class]
142 questions
1
vote
2 answers
Sealed class with existing classes?
I am implementing a custom keyboard and I am representing the keys 0-9 and the decimal separator as Button objects. Then I have one final key which is the backspace and is being represented as an ImageButton.
When I handle the click events I know…

nicoqueijo
- 872
- 2
- 11
- 28
1
vote
1 answer
Kotlin : Why *unresolved reference* for a constructor parameter of a subclass of a sealed class
sealed class Person () {
data class Man (val name: String): Person()
data class Woman (val name: String): Person()
fun stringOf(): String {
return when (this) {
is Person.Man -> "Mr "+this.name
is Person.Woman ->…

Emile Achadde
- 1,715
- 3
- 10
- 22
1
vote
1 answer
Encryption and decryption of sealed object in different java services throws classNotFoundException
I'm encrypting employee class below using AES and saving it as sealedObject as part of serviceA.
org.company.serviceA.model.employee;
class employee{
Integer ssn;
String name;
}
org.company.serviceB.model.employee;
class employee{
Integer…

Shrihari
- 23
- 3
1
vote
2 answers
Why does the ordering of the unsealed class`s unsealed virtual methods calls matter?
Why does the ordering of the unsealed class`s unsealed virtual methods calls matter?
I am exploring the CLR via C# book and I come across the following excerpt:
When a class is originally sealed, it can change to unsealed in the future without
…

qqqqqqq
- 1,831
- 1
- 18
- 48
1
vote
3 answers
Kotlin sealed class and type inference
im using a sealed class to report back success or error to client code:
sealed class Result {
data class Success(val data: T) : Result()
data class Error(val exception: Exception) : Result()
}
But im…

Kitesurfer
- 3,438
- 2
- 29
- 47
1
vote
1 answer
Using Kotlin Sealed Classes for routing to different screens
Is it a good idea to create sealed classes as such:
sealed class Route {
data class ToRoute1(val data: T) : Route()
data class ToRoute2(val data: T) : Route()
data class ToRoute3

Archie G. Quiñones
- 11,638
- 18
- 65
- 107
1
vote
1 answer
sealed keyword prevents inheritance of a class
sealed keyword prevents inheritance of a class. Inheritance is one of the feature of object oriented program. Does it mean sealed is not oops concept?

thegautamnayak
- 287
- 4
- 15
0
votes
0 answers
Kotlin, sealed classes, children do not have to extend the parent class
There is no information about this in the official Kotlin docs, or I've missed it (here: https://kotlinlang.org/docs/sealed-classes.html)
Although through testing I assume that my understanding is correct:
you can omit specifying the supertype of…

Tim Kochetkov
- 149
- 1
- 11
0
votes
1 answer
Sealed class objectInstance R8 null problem
I have a selaed class that contains object like;
sealed class Item(val route:String,val showTopBar: Boolean = false) {
object Example1: Item(route = "example1")
object Example2: Item(route = "example2", showTopBar = true)
}
When I want to get…

emreturka
- 846
- 3
- 18
- 44
0
votes
1 answer
com.fasterxml.jackson.databind.exc.MismatchedInputException: Kotlin sealed class Json Mapping
Using Spring Boot with Kotlin, Deserialization of this sealed class works for Range type but fails for Exactly type. The serialization works fine but the deserialization doesn't work.
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include =…

Ayoub
- 361
- 4
- 15
0
votes
0 answers
Kotlin Sealed Class callback
To complete a main operation, it is necessary to complete several sub operations.
I can say that each operation has its own tasks such as starting, processing and stopping.
The structure for a single operation as below:
sealed class DenemeState {
…

Metropol_Tilkisi
- 349
- 7
0
votes
0 answers
Kotlin nested sealed classes for mapping enums
I have an extensive class hierarchy that I want to map to an existing enum type. Given this example hierarchy:
open class A {
open class BB: A() {
class CCC: BB(){}
class DDD: BB(){}
}
}
I want to map the class type from the…

jorge-plaza
- 21
- 5
0
votes
1 answer
How to control what classes can extend my class in Java
So I was asked this question in interview that if I have a class A how do I restrict which classes will be able to extend A. For example if I want only class C and E to be able to extend A and classes B and D should not be able to do so. I mentioned…

Shivam...
- 409
- 1
- 8
- 21
0
votes
1 answer
How to use sealed classes with generics in kotlin
I can't find a solution to this problem
data class Data(val s: String)
sealed class Base(val t: T, val f: Base.() -> Unit)
class A(data: Data, f: A.() -> Unit) : Base(data, f)
Type mismatch.Required:Base.() → Unit Found: A.() →…
0
votes
1 answer
Mapping sealed class using Gson
I am getting the following error whilst trying to map an incoming REST-api result in Json to an object :
failed to invoke private kotlinx.serialization.json.jsonelement() with no args
After some searching the problem seems to be that I am trying to…

TiGer
- 5,879
- 6
- 35
- 36