Questions tagged [sealed]

The sealed modifier keyword prevents a C# class from being inherited. Similar to the final keyword in Java.

The sealed modifier keyword prevents a C# class from being inherited. Similar to the final keyword in Java.

183 questions
1
vote
1 answer

Add methods to a dll class

Here is my problem : I have a dll containing some mathematical functions, the code looks that way: internal sealed class TemplateSourceCodeClass { public const string MathExpressionEvaluationCode = @"using System; class…
user2492258
  • 11
  • 1
  • 3
1
vote
2 answers

Sealed classes and Object Browser

While inspecting the the .net object model in the Object Browser window, I came across the lack of information on sealed classes. If for instance, one navigates to the mscorlib container -> System namespace -> String class, the details pane displays…
Alexandre Bell
  • 3,141
  • 3
  • 30
  • 43
1
vote
1 answer

Reflection not extracting values from: Sealed Class having a property, which is object of another sealed class.

I am recrusively evaluating properties via reflection using object.GetType().GetProperty(string propertyName). This is working fine in case the obj is of sealed class but having property as an object of normal public class. However if this property…
Ashish Jain
  • 4,667
  • 6
  • 30
  • 35
0
votes
0 answers

Specializing Generic Sealed Types. Part 1

Suppose I want a generic abstract tree type and then want to specialize it to create specific types of trees. For example I might have: sealed abstract class AST[T <: AST[T]] { def child : List[T] ; } case class LeafAST[T <: AST[T]]( x : Int )…
Theodore Norvell
  • 15,366
  • 6
  • 31
  • 45
0
votes
1 answer

Kotlin Sealed Classes

I am new to Kotlin Programming What are the real time examples of Sealed Classes. If the implemented classes are not sealed then it can be further inherited. What's the use in it?. Is Sealed class same as default modifier in java. (Except the when…
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

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

Java Sealed Classes and Coupling

When programming, there are many indicators that coupling is bad. A class should know as little as possible about other classes. So it is modular and can easily be replaced. Now, with the introduction of sealed classes, the abstract super-class…
user16612231
0
votes
2 answers

How can tweaks to existing methods in an auto-generated C# partial class be persisted?

I am working with Visual Studio Coded UI Tests, and wish to persist tweaks to the generated code. The code is generated as a partial class in UIMap.cs and UIMap.Designer.cs, and so I know one solution would be to create a method with a slightly…
theheadofabroom
  • 20,639
  • 5
  • 33
  • 65
0
votes
1 answer

In Java 16+, Is there any reason why a class sealed to a single child class can't access methods from that child?

As a concrete example sealed interface A permits B { default void a() { this.b(); } } non-sealed interface B extends A { void b(); } I know that this does not compile, but from a language perspective i don't understand what…
Ethan McCue
  • 883
  • 1
  • 8
  • 17
0
votes
3 answers

Pattern to avoid if else chain methods call using kotlin sealed class and enums

I've a question about, how would you handle this case? Imagine that you have to do a validation of an object and that validation should have a sort of importance, in this case we only have 3 validations, each one can result Valid or his own…
colymore
  • 11,776
  • 13
  • 48
  • 90
0
votes
2 answers

Can't errors related with instantiating / inheriting class be treated by try~catch statement?

I hope to run the below C# codes to practice usage of abstract / sealed classes : using System; abstract class Person // abstract : can be inherited but can't be instantiated { public Person() { Console.Write(this + " : "); …
Kimpro
  • 81
  • 2
  • 11
0
votes
1 answer

Pass a sealed class as function argument android

I have a sealed class which represents the Retrofit Response of my API. sealed class NetworkResponse { data class Success(val body: T) : NetworkResponse() data class ApiError(val…
james04
  • 1,580
  • 2
  • 20
  • 46
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

Why does C# allow me to declare a default interface implementation as "sealed", but then behave inconsistently when I do?

New C# .NET Core Console App: using System; namespace Interface_Sealed { class Program { static void Main(string[] args) { Console.WriteLine(new C().X); Console.WriteLine((new C() as I).X); …
Hammerite
  • 21,755
  • 6
  • 70
  • 91