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
23
votes
3 answers

Sealed classes inside another class in Kotlin can't be compiled: cannot access '' it is private

If I used the example from the docs, class SomeActivity : AppCompatActivity() { sealed class Expr data class Const(val number: Double) : Expr() data class Sum(val e1: Expr, val e2: Expr) : Expr() object NotANumber : Expr() } it…
Randy Sugianto 'Yuku'
  • 71,383
  • 57
  • 178
  • 228
23
votes
2 answers

Why isn't List sealed?

This question came to mind after reading the answer to this question; which basically made the point that List has no virtual methods, since it was designed to be "fast, not extensible". If that's the design goal, why didn't the original design…
Pierreten
  • 9,917
  • 6
  • 37
  • 45
21
votes
3 answers

C# sealed vs Java final

Would anybody please tell me as the reason the following use of sealed does not compile? Whereas, if I replace sealed with final and compile it as Java, it works. private sealed int compInt = 100; public bool check(int someInt) { if (someInt >…
Saurabh Ghorpade
  • 1,137
  • 5
  • 15
  • 22
17
votes
5 answers

Mocking a method that returns a sealed class in RhinoMocks

Running this code: _foo = MockRepository.GenerateStub(); _foo.Stub(x => x.Foo()).Return("sdf"); When public interface IBar { string Foo(); } public class Bar : IBar { public string Foo() { throw new NotImplementedException(); …
ripper234
  • 222,824
  • 274
  • 634
  • 905
17
votes
1 answer

TypeConverter Attribute for Third Party Classes

When creating a class, a TypeConverter attribute can be applied to it s.t. using TypeDescriptor.GetConverter(typeof(T)) return the custom type converter. For instance: [TypeConverter(typeof(FooConverter))] public class Foo {...} public class…
TRISAbits
  • 455
  • 4
  • 9
16
votes
8 answers

Why does the 'sealed' keyword exist in .Net?

A large number of classes in the .Net framework are marked as 'sealed', preventing you from inheriting those classes with your own. Surely this goes against the nature of object orientation, where you can extend and redefine the behaviour of…
X-Cubed
  • 1,869
  • 15
  • 24
14
votes
4 answers

What are the 'ref' and 'sealed' keywords in C++?

I've just seen some (presumably) C++ code which sports two "keywords" unknown to me (I'm assuming keywords but, since I have no context, they may be simple #define things). They also don't seem to appear in the C++11 standard, at least the draft I…
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
14
votes
2 answers

Can I make a type "sealed except for internal types"

I want to make a type that can be inherited from by types in the same assembly, but cannot be inherited from outside of the assembly. I do want the type to be visible outside of the assembly. Is this possible?
Lucas Meijer
  • 4,424
  • 6
  • 36
  • 53
13
votes
2 answers

Can class fields be sealed?

In the MSDN C# programming guide, it is mentioned that: "A class member, method, field, property, or event, on a derived class that is overriding a virtual member of the base class can declare that member as sealed." I understand the above…
user1510194
  • 371
  • 1
  • 2
  • 14
13
votes
5 answers

Python's equivalent of .Net's sealed class

Does python have anything similar to a sealed class? I believe it's also known as final class, in java. In other words, in python, can we mark a class so it can never be inherited or expanded upon? Did python ever considered having such a feature?…
cregox
  • 17,674
  • 15
  • 85
  • 116
13
votes
1 answer

Cannot be sealed because it's not an override

I've the following class: namespace Warnings { public abstract class BaseWarningIntField : IWarningInnerDataField { public string PropName; public string HeaderCaption; public sealed WarningInnerDataType DataType …
Teejay
  • 7,210
  • 10
  • 45
  • 76
12
votes
5 answers

Do the access levels and modifiers (private, sealed, etc) serve a security purpose in C#?

I've seen that you can manipulate private and internal members using reflection. I've also seen it said that a 'sealed' class is more secure that one that isn't. Are the modifiers "public, protected, internal, private, abstract, sealed, readonly"…
MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
12
votes
2 answers

Are sealed classes enforced in Java and, if yes, how?

It is possible to define sealed classes in Scala, which are basically final except if the sub-classing happens in the same file. It seems that the JVM doesn't allow final class bytecode and subclasses of it. Considering that there is no "notion" of…
soc
  • 27,983
  • 20
  • 111
  • 215
12
votes
2 answers

Is there any functional difference between c# sealed and Java's final keyword?

Possible Duplicate: What is the equivalent of Java’s final in C#? In Java final applies to more than just a class. So, I wonder: is there any functional difference between the two keywords? Thank you, and sorry for a relatively noob question. A…
Hamish Grubijan
  • 10,562
  • 23
  • 99
  • 147
12
votes
3 answers

mockito vs sealed packages

I'm working on a project with heavy security constraints. A requirement is to seal our jars. Since we sealed jars, a lot of our junit-tests failed with the following error : java.lang.SecurityException: sealing violation: package…
Syrdek
  • 123
  • 4
1
2
3
12 13