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
6
votes
2 answers

Is the permits relationship of Java Sealed classes/interfaces transitive

If I read the JLS §8.1.6 and §9.1.4 correctly, the classes that a sealed class/interface permits, are just the direct subclasses/interfaces. To illustrate this, consider the following example: public sealed interface I1 permits I2, C, D { /*...*/…
twwwt
  • 438
  • 1
  • 4
  • 16
6
votes
3 answers

Is the sealed command c++ 0x or is it only microsoft who has it

Is the sealed command going to be in c++ 0x or is it only MS who use it?
Merni
  • 2,842
  • 5
  • 36
  • 42
6
votes
1 answer

Decrypt data using AES.GCM.SealedBox in Swift

I am trying to decrypt data using AES.GCM.The encrypted data works fine but when I try to decrypt the data using the same key it gives authentication error. Below is the code to decrypt func decryptData(decryptToData: Data, key: SymmetricKey) ->…
md12
  • 111
  • 1
  • 8
6
votes
2 answers

Achieving the effect of a sealed class in Swift

I'm trying to achieve the effect of Kotlin sealed class in Swift, so that I can implement a class-based alternative to enums with associated types. The following results in a compiler error: final class Foo { class Bar: Foo {} // Error:…
Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
6
votes
0 answers

Evidence for sealed class performance benefit

Possible Duplicate: Do sealed classes really offer performance Benefits? My team is wrestling with the sealed class debate internally and I would like to simplify the debate down to a matter of design and get the performance myth off the debate…
camelCase
  • 61
  • 1
6
votes
3 answers

What is the purpose of "sealed" in C# when "virtual" is optional?

If a class doesn't have any virtual methods, I do not see any way inheriting a class would affect any code that doesn't explicitly refer to the instance as an instance of the subclass i.e. Subclass obj = new Subclass() rather than BaseClass obj =…
flarn2006
  • 1,787
  • 15
  • 37
6
votes
7 answers

Change "ToString" for a sealed class

I have a class I am working with: public sealed class WorkItemType It's ToString is weak (Just shows Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType). Is there any way to override this to show the name of the WorkItemType? Normally I…
Vaccano
  • 78,325
  • 149
  • 468
  • 850
6
votes
1 answer

Why can an abstract class not be sealed or static?

Why can an abstract class not be sealed or static? And I am also confused about the question Why declare static classes as sealed and abstract in C#?.
anomepani
  • 1,796
  • 2
  • 25
  • 34
5
votes
1 answer

When are sealed classes and records used together in Java?

JEP on sealed classes says : Sealed classes do not depend on records (JEP 384) or pattern matching (JEP 375), but they work well with both. What does it mean "work well"? Are there any recommendations to use the combination in some specific cases?
Serhii Povísenko
  • 3,352
  • 1
  • 30
  • 48
5
votes
2 answers

How to implement ViewHolder using sealed class in Kotlin

I saw an interesting viewholder implementation in this tweet https://twitter.com/AndroidDev/status/972502799496790018 override fun onBindViewHolder(holder: SealedAdapterViewHolder, position: Int) { return when (holder) { is HeaderHolder ->…
Maksim Turaev
  • 4,115
  • 1
  • 29
  • 42
5
votes
1 answer

Why is the ASP.NET ListItem class sealed?

I'm just curious. Why would the ASP.NET ListItem class need to be sealed?
John K
  • 28,441
  • 31
  • 139
  • 229
5
votes
5 answers

C#: Mocking and testing protected (or private) methods in sealed classes -- approaches

I have a sealed class with protected methods whose behaviour I want to test. This makes it hard to test directly, and hard to mock. It's in a codebase that wasn't developed in a TDD manner, and I'm now adding unit tests for specific…
Tim Barrass
  • 4,813
  • 2
  • 29
  • 55
5
votes
1 answer

Abstract Sealed Classes

Just a small question about c++/cli. Abstract classes have abstract methods to be implemented by derived classes, sealed classes dont allow inheritance. So why we have some classes in .NET base class library defined as abstract sealed, and you can…
Ibrahim Najjar
  • 19,178
  • 4
  • 69
  • 95
5
votes
5 answers

How can I XML Serialize a Sealed Class with No Parameterless Constructor?

I'm currently using an XMLSerializer to serialize a list of a class of my own. One of the class's properties is an instance of a sealed class that does not have a parameterless constructor, so the XML Serializer refuses to serialize the class. How…
NickAldwin
  • 11,584
  • 12
  • 52
  • 67
5
votes
1 answer

Scala json4s sealed trait as enums

We have our status defined as: sealed trait Status case object Status { case object StatusA extends Status case object StatusB extends Status case object StatusC extends Status } Our status looks like: val status = Status.StatusA Is there…
zmeda
  • 2,909
  • 9
  • 36
  • 56