草庐IT

inherited

全部标签

inheritance - 是否可以将 Swift 泛型类函数返回类型限制为同一个类或子类?

我正在Swift中扩展一个基类(我无法控制的基类)。我想提供一个类函数来创建一个类型为子类的实例。需要通用函数。但是,像下面这样的实现不会返回预期的子类类型。classCalculator{funcshowKind(){println("regular")}}classScientificCalculator:Calculator{letmodel:String="HP-15C"overridefuncshowKind(){println("scientific")}}extensionCalculator{classfunccreate()->T{letinstance=T()ret

Java 泛型 : Multiple Inheritance in Bounded Type Parameters <T extends A & I>

我将要创建一个工厂,它创建某种类型T的对象,它扩展了某个类A和另一个接口(interface)I。但是,T一定是未知的。以下是最低限度的声明:publicclassA{}publicinterfaceI{}这是工厂方法:publicclassF{publicstaticTnewThing(){/*...*/}}编译一切正常。当我尝试使用以下方法时,效果很好:A$a=F.newThing();...虽然这不是:I$i=F.newThing();编译器提示:Boundmismatch:ThegenericmethodnewThing()oftypeFisnotapplicableforth

java - 避免在 Java 中重复导入 : Inherit imports?

有没有办法“继承”导入?示例:常用枚举:publicenumConstant{ONE,TWO,THREE}使用这个枚举的基类:publicclassBase{protectedvoidregister(Constantc,Stringt){...}}需要导入的子类方便地使用枚举常量(没有枚举名称):importstaticConstant.*;//wanttoavoidthisline!publicSubextendsBase{publicSub(){register(TWO,"blabla");//withoutimport:Constant.TWO}}和另一个具有相同导入的类...

java - "inherited"是解释父类(super class)的静态方法可以被子类访问的正确术语吗?

澄清:这个问题不是关于访问修饰符的已确认B.m()和b.m()语句都适用于以下代码:classA{staticvoidm(){//somecode}}classBextendsA{}classExample{publicstaticvoidmain(String[]args){B.m();//runningA'sm()staticmethod}publicvoidtry(){Bb=newB();b.m();//runningA'sm()staticmethod}}我的问题是我们可以说“静态方法是继承的”吗?如果“继承”是正确的术语,如果我们向B类添加一个方法,我们将使用静态类的相同签名

java - 保留 CGLIB 代理上的注释?

我正在尝试使用AOP框架创建对象,该框架使用CGLIB创建代理对象。奇怪的是,“增强型”代理对象没有任何前一类的注释!谁能告诉我如何让CGLIB保留其创建的代理上的注释?干杯!尼拉夫 最佳答案 CGLIB创建给定类的子类以生成代理。除非在注释定义中明确指定,否则注释不会保留在子类中。@Inherited注释用于此目的。您可以在您定义的注解中使用该注解,并使它们在子类中可达,如下所示:@Inherited@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.TYPE)public

java - 泛型 : Inheriting from an abstract class that implements an interface

我有以下界面:publicinterfaceSingleRecordInterface{publicvoidinsert(Tobject);}我有下面的抽象类(没有提到插入方法):publicabstractclassAbstractEntryimplementsSingleRecordInterface{}我有具体的类:publicclassSpecificEntryextendsAbstractEntry{publicvoidinsert(SpecificEntryBeanentry){//stuff}}最后,SpecificEntryBean定义为:publicclassSpec

python - multiprocessing.Process(使用 spawn 方法): which objects are inherited?

文档(python3.4)解释说,使用spawn,“子进程将仅继承运行进程对象的run()方法所需的那些资源”。但是哪些对象是“必要的”?我阅读它的方式向我表明,可以从run()内部访问的所有对象都是“必需的”,包括作为args传递给Process的参数.__init__,以及存储在全局变量中的任何内容,以及在全局范围内定义的类、函数及其属性。但是,这是不正确的;以下代码确认存储在全局变量中的对象没有被继承:#runningunderpython3.4/Windows#butbehavesthesameunderUniximportmultiprocessingasmpx=0class

python - Sphinx autodoc show-inheritance : How to skip undocumented, 中间基础?

我有一个像这样的三层类结构:classSuper(object):"""Thisclassisdocumented."""classIntermediate(Super):passclassSub(Intermediate):"""Thisisalsodocumented."""我的index.rst文件如下所示:..automodule::mymodule:show-inheritance::inherited-members:Sphinx为我生成了一份不错的API文档。它包括类Super和Sub,并带有适当的注释。它不包括Intermediate,因为它没有注释而且我没有提供und

html - 样式 css 宽度 :inherit?

我有一些元素是从我的父div中获取的。为什么?这是我的CSS:.lightboximg{margin-top:2%;}.viewer-v3.lightbox{overflow:auto;display:block;position:fixed;z-index:9999;width:100%;height:100%;text-align:center;top:0;left:0;background:black;background:rgba(0,0,0,0.8);}.viewerimg{margin-top:2%;max-width:100%;margin-bottom:2%;}.bor

html - 样式 css 宽度 :inherit?

我有一些元素是从我的父div中获取的。为什么?这是我的CSS:.lightboximg{margin-top:2%;}.viewer-v3.lightbox{overflow:auto;display:block;position:fixed;z-index:9999;width:100%;height:100%;text-align:center;top:0;left:0;background:black;background:rgba(0,0,0,0.8);}.viewerimg{margin-top:2%;max-width:100%;margin-bottom:2%;}.bor