Questions tagged [sealed-class]

142 questions
2
votes
1 answer

Canonical way to represent idea of sum type of records that all extend a "base" record

I'm new to PureScript. I was searching for sealed classes in Purescript to get an idea of how one would implement this, but I don't think I have the necessary PS jargon yet. What is the canonical way in PureScript to have a bunch of records that…
2
votes
1 answer

sealed class extends other sealed class

I am making various state models and side effect classes while using the MVI pattern. The state model can reduce the boilerplate by extending the interface that collects common parts, but the side effect class does not support extends as it is a…
Ji Sungbin
  • 891
  • 1
  • 10
  • 19
2
votes
2 answers

How and when to use Kotlin sealed classes in Java?

Thinking about misusing sealed classes, let's look at the following design. There are two modules: parser (Kotlin) - is responsible for making instances from String processor (Java) - pumps over raw incoming data into a strongly typed storage (i.e.…
diziaq
  • 6,881
  • 16
  • 54
  • 96
2
votes
1 answer

Android Studio not recognising that a when statement is exhaustive with a sealed class

I have a simple result class called Outcome which is sealed and consists of three subclasses: Waiting, Success and Failure: sealed class Outcome { object Waiting : Outcome() class Success(val data: T) : Outcome() …
Henry Twist
  • 5,666
  • 3
  • 19
  • 44
2
votes
0 answers

how to write Mongo type query with Kotlin sealed class

I want to access Mongo DB using Kotlin with the help of Kmongo (litote.org) plugins and I only want to write Kmong Typed query. https://litote.org/kmongo/typed-queries/ My Kotlin data classes are below: data class Student( studentId:ObjectId, …
shriyash Lakhe
  • 607
  • 1
  • 9
  • 21
2
votes
2 answers

Kotlin Sealed Class of same Classes

A KorGE Game Library example game (CounterStrike) has the following construct: sealed class SideEffect{ class Hit() : SideEffect() class TerroristShot(val terrorist: Terrorist) : SideEffect() class KillTerrorist(val terrorist:…
2
votes
2 answers

Resource wrapper sealed class, error with databinding

I'm stuck on a little issue using Resource wrapping around my data, I don't know how I can use it in my databinding. Sealed class: sealed class Resource { data class Success(val data: T): Resource() data class…
Biscuit
  • 4,840
  • 4
  • 26
  • 54
2
votes
0 answers

Understanding Sealed Classes In Kotlin - Non-top-level sealed class is not visible accross file

I am currently studying kotlin's sealed classes According to the documentation A sealed class can have subclasses, but all of them must be declared in the same file as the sealed class itself However, my testing seems to suggest that there is…
user5132301
2
votes
0 answers

Scala's sealed in python

How might I get the benefits of scala's sealed class in python? That is, to make it possible to subclass a class only in the module in which it's defined. Note not a dupe of this post. C# sealed is equivalent to scala's final. An example of where I…
joel
  • 6,359
  • 2
  • 30
  • 55
2
votes
1 answer

Access the set of abstract properties on sealed sub classes (in kotlin)

I'm got a situation where I have a common property that must be defined on each of the subclasses of a sealed class. I'd like the ability to be able to access the set/list of these values without 'duplicating' the list (by hard coding it) Hopefully…
Morgan
  • 303
  • 2
  • 15
2
votes
1 answer

Calling Kotlin function with parameter as sealed class from java

My Kotlin class TimeUtils has a sealed class declared as: sealed class TimeUnit { object Second : TimeUnit() object Minute : TimeUnit() fun setTimeOut(timeout : TimeUnit) { // TODO something } My Java class is calling setTimeOut…
Kushal
  • 8,100
  • 9
  • 63
  • 82
2
votes
1 answer

Type safe usage of generic sealed classes

I found interesting thing when I write generic sealed class. Here is first version: // sample interface and implementation interface MyInterface class MyInterfaceImpl : MyInterface sealed class Response data class…
2
votes
2 answers

Missing identity field with polymorphic (de)serialisation in Kotlin with Jackson

I have the following class hierarchy annotated as such: @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes( JsonSubTypes.Type(value = NetCommand.AddEntity::class, name = "AddEntity"), …
dave
  • 1,127
  • 2
  • 10
  • 26
2
votes
3 answers

Why do we need sealed classes?

I know the functionality of a Sealed class. That its not inheritable. But my question is why do we need a Sealed Class? If not inheriting properties and methods is the motive, why don't just declare them as private?
2
votes
1 answer

passing a generic type to a nested sealed class

Is it possible? How can I expain to the compiler that its the same type (BR) extending the same class? The code bellow fails class BaseRepository() { sealed class BaseSealedResponse { open class Success(val receivedValue: BR) …
Jack
  • 1,545
  • 2
  • 11
  • 20