本文介绍了为什么不类默认情况下,封了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道,因为在密封关键字的存在表明它是类作者的决定为其他类是否允许继承它,为什么不类默认密封,用一些关键字给他们明确地标记为可扩展的?

I was just wondering, since the sealed keyword's existence indicates that it's the class author's decision as to whether other classes are allowed to inherit from it, why aren't classes sealed by default, with some keyword to mark them explicitly as extensible?

我知道这有些不同,但访问修饰符以这种方式工作。缺省设置为严格,更全面的访问仅授予与关键字插入。

I know it's somewhat different, but access modifiers work this way. With the default being restrictive and fuller access only being granted with the insertion of a keyword.

还有,我没有通过正确觉得这是个机会很大,虽然,所以请人性化!

There's a large chance that I haven't thought this through properly, though, so please be humane!

推荐答案

我认为不应该有默认的语法,这样你总是写明确你想要什么。这迫使codeR理解/多想。

In my opinion there should be no default syntax, that way you always write explicitly what you want. This forces the coder to understand/think more.

如果你想那么你就写一个类是继承

If you want a class to be inheritable then you write

public extensible class MyClass

,否则

public sealed class MyClass

BTW我认为同样应该访问修饰符去,不允许默认访问修饰符。

BTW I think the same should go with access modifiers, disallow default access modifiers.

这篇关于为什么不类默认情况下,封了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:48