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

Reference outside the sealed class in Kotlin?

I'm trying to create a class that uses its own state to operate on the state of an external object that it holds a reference to. The external object can be of class A or B, which are similar, but not controlled by the author. So a sealed class is…
sirksel
  • 747
  • 6
  • 19
2
votes
1 answer

C++ Final or Sealed

Consider the following class: class X { }; One can easily inherit from this: class Y : public X { }; Okay so far... Let's say we don't want anyone to inherit from Y we can then do this instead. class Y sealed : public X { }; Or we could do…
Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
2
votes
3 answers

Why can I seal a class implementing an interface but cant seal a member?

Given this interface public interface IMyInterface { string Method1(); } Why is this valid public sealed class InheretedFromInterfaceSealed: IMyInterface { public string Method1() { return null; } } But this isnt public…
Simon
  • 33,714
  • 21
  • 133
  • 202
2
votes
2 answers

Access internal method in a sealed class C#

I'm trying to access an Internal Method in a sealed class but since it is a sealed class, I'm not able to inherit the Internal Method. The backend portion of the solution I'm working on is designed like that. I found a work around for this which…
Arden
  • 51
  • 2
  • 5
2
votes
1 answer

Why are some classes in the CLR sealed?

I've recently been using the System.Version class and have wondered why it, and some other similarly simple enough classes, are marked as Sealed (NotInheritable in VB). Unlike some more complex classes I don't see what such a class would gain by…
Toby
  • 9,696
  • 16
  • 68
  • 132
2
votes
2 answers

Scala - Create a List of case objects that extend an sealed abstract class

I'm trying to create a List of case objects in a companion object. The objects all inherit from a sealed abstract class. But the compiler is saying "not found: value CompositeSpectrum" and so on for each item in the List. The sealed class and case…
Bill Davis
  • 25
  • 1
  • 6
2
votes
1 answer

How to write an immutable TallySet (counting multiset) in FSharp

I am trying to create an immutable collection type that behaves as a hybrid of multiset/bag and Map that records the number of occurrences of each item. I can write a mutable one with code a little like below and I tried to write an immutable one…
2
votes
1 answer

What part of LINQ to SQL's provider model makes it impossible to extend it to support third party (read: Non-Microsoft) databases?

There were supposedly some classes in the LINQ to SQL provider model that were sealed--but I never really figured out exactly which classes need to be 'unsealed' in order to use it. Hypothetically speaking, which classes do I need to unseal to…
plaureano
  • 3,139
  • 6
  • 30
  • 29
2
votes
3 answers

How can I Databind to a Sealed Class?

I'm trying to bind some WPF controls to a sealed class provided to me. Because it is sealed, I cannot inherit from it to create a class that implements INotifyPropertyChanged. So I'm not sure how I should go about doing this. Should I create a…
NickAldwin
  • 11,584
  • 12
  • 52
  • 67
2
votes
2 answers

Scala : Compiler emits no warning when pattern matching against a sealed trait

Here is a snippet. When pattern matching, compiler emits no warning. Do you know any workaround ? I would like the compiler to emit warning when I forget a case when pattern matching against SimpleExpr.Expr and OtherExpr.Expr. This construct allows…
Julien__
  • 1,962
  • 1
  • 15
  • 25
2
votes
4 answers

Why is the sealed keyword not included in the list of access modifiers?

I think sealed should be included in the list of access modifiers in C# language. Can somebody tell the reason why it has been excluded?
Ashish Jain
  • 4,667
  • 6
  • 30
  • 35
2
votes
6 answers

C# Sealed Prevent a method to be derived

I'm trying to prevent my Base Class to derived one of its method, but it seems impossible to do it in the way I like, I assume I'm doing it wrong. Could you help please ? :) I really want to use successfully the sealed keyword ! Here is a bit of…
Fikkwix
  • 167
  • 3
  • 10
2
votes
3 answers

can a derived class corrupt base class's implementation

I am kind of new to c# and was studying about sealed class, when i came across this 'A sealed class is mostly used for security reasons by preventing unintended derivation by which the derived class may corrupt the implementation provided in the…
Arun
  • 145
  • 1
  • 7
2
votes
0 answers

How do I dynamically obtain the set of classes implemented for a sealed trait using object.getClass (as opposed to using a type parameter)?

Summary: Using an object which contains both a sealed trait and all of its implementers, how can obtain the set of the class names of all the sealed trait implementers using the the containing object's getClass method (as opposed to using a type…
chaotic3quilibrium
  • 5,661
  • 8
  • 53
  • 86
2
votes
1 answer

Is it possible to seal classes in a jar file?

So I know it is possible to seal a package in a jar file by setting the sealed attribute to true but is it possible to do the same with class entries in the manifest? Will this sealed attribute below work if Boot.class exists or is sealed only meant…