标签: extends

在一个类打字稿中扩展和实现

我能用打字稿做这个吗?

export interface IMyInterface {
    doSomething():void;
}

export class MyBaseClass {
    myBaseClassHasProperty:string;

    constructor(){
      this.myBaseClassHasProperty = 'some value';
    }
    myBaseClassHasMethods():void{
      console.log(this.myBaseClassHasProperty);
    }
}

export class MyClass extends MyBaseClass implements IMyInterface {
    constructor(){
      super();
    }

    doSomething():void{
      this.myBaseClassHasMethods();
    }
}
Run Code Online (Sandbox Code Playgroud)

在运行时我得到这个

未捕获的ReferenceError:未定义MyBaseClass

extends implements typescript

26
推荐指数
1
解决办法
2万
查看次数

当我的测试类使用自己的构造函数方法时,PHPUnit 6.1.x会抛出array_merge()错误

我收到此错误:

1) XTest::testX
array_merge(): Argument #1 is not an array

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Run Code Online (Sandbox Code Playgroud)

在这个测试案例中:

use PHPUnit\Framework\TestCase;

class XTest extends TestCase
{

    function __construct()
    {}

    function testX()
    {
        $this->assertTrue(true);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我删除__construct方法,我的测试通过.PHPUnit处理我的类构造函数方法会发生什么?它在PHPUnit版本4.8中运行良好,但现在我使用PHPUnit版本6.1.3

php phpunit constructor extends

24
推荐指数
2
解决办法
4757
查看次数

Typescript 继承:扩展基类对象属性

当扩展一个类时,我可以轻松地向它添加一些新属性。

但是,如果当我扩展基类时,我想向基类的对象(简单对象的属性)添加新属性怎么办?

这是一个带有一些代码的示例。

基类

type HumanOptions = {
  alive: boolean
  age: number
}

class Human {
  id: string
  options: HumanOptions

  constructor() {
    this.id = '_' + Math.random()

    this.options = {
      alive: true,
      age: 25,
    }

  }
}
Run Code Online (Sandbox Code Playgroud)

派生类

type WizardOptions = {
  hat: string
} & HumanOptions

class Wizard extends Human{
 
  manaLevel: number
  options: WizardOptions // ! Property 'options' has no initializer and is not definitely assigned in the constructor.

  constructor() {
    super()
    this.manaLevel = 100
    this.options.hat = "pointy" // …
Run Code Online (Sandbox Code Playgroud)

inheritance extends class object typescript

24
推荐指数
2
解决办法
6561
查看次数

23
推荐指数
2
解决办法
6万
查看次数

如何在Eclipse中找到重写的方法?

当我在eclipse中查看一个方法时,如何跳转到覆盖/扩展的方法?

java eclipse extends

20
推荐指数
2
解决办法
7128
查看次数

扩展base.html问题

我收到以下错误:

Template error

In template /home/mo/python/django/templates/yoga/index.html, error at line 1
Caught TemplateDoesNotExist while rendering: base.html
1 {% extends "base.html" %}
2 
3 {% block main %}
4     <p>{{ page.title }}</p>
5     <p>{{ page.info}}</p>
6     <a href="method/">Method</a>
7 {% endblock %}
8 
Run Code Online (Sandbox Code Playgroud)

这是我的base.html文件,它与index.html位于同一个位置

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <div style="width:50%; marginleft:25%;">
    {% block main %}{% endblock %}
    </div>
Run Code Online (Sandbox Code Playgroud)

到底发生了什么?base.html文件应该位于其他地方吗?

django templates extends

19
推荐指数
3
解决办法
3万
查看次数

对于java参数/返回类型,C++相当于使用<T extends Class>

在java中,要创建一个返回与参数类型相同的对象并扩展某个类的函数,我会输入:

public <T extends MyClass> T foo(T bar) {...}
Run Code Online (Sandbox Code Playgroud)

有没有C++相当于此?

换句话说,我如何创建一个函数,它接受任何扩展某个类的类,并返回相同的类型?(这是为了抽象/纯虚拟类的目的).

c++ java generics extends

19
推荐指数
4
解决办法
1万
查看次数

Java:当foo()在超类中时,this.foo()和super.foo()是否相同?

说我有以下课程:

class Foo {
    protected void method() {}
}

class Bar extends Foo {

}
Run Code Online (Sandbox Code Playgroud)

此时,从类Bar,我可以通过method()两种方式访问:

  • super.method();
  • this.method();

从我看来,他们似乎执行相同的行动.在这种情况下,这两者之间是否存在差异?是否有首选版本可供使用?

使用super是有道理的,因为它method()是超类的一部分.this我认为使用也很有道理,因为Bar将继承Foo类的属性,因此method(),对吧?

java extends this super

19
推荐指数
2
解决办法
1096
查看次数

在Android中使用BaseActivity的不同活动中的Common Header

我想要一次编写代码并在不同的活动中使用.我Base Activity class为此创造了一个.此外,不同活动中所有布局的标题都是相同的.我已经在<include layout >标签的帮助下完成了这项工作.

现在的问题是我的BaseActivity代码没有运行.我这是第一次尝试这个没有太多想法.

1.)BaseActivity代码如下:

package com.waheguru.app;

import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import android.view.View;
import android.view.View.OnClickListener;

import android.widget.Button;
import android.widget.Toast;

public abstract class BaseActivityMenu extends Activity {
    //action id
    private static final int ID_UP     = 1;
    private static final int ID_DOWN   = 2;
    private static final int ID_SEARCH = 3;
    private static final int ID_INFO   = 4;
    private static final int ID_ERASE  = 5; 
    private static final int ID_OK …
Run Code Online (Sandbox Code Playgroud)

android extends android-layout

18
推荐指数
1
解决办法
2万
查看次数

稍后在同一文件中定义的派生类"不存在"?

假设我们有两个php文件,a.php和b.php这里是文件a.php的内容:

<?php // content of a.php
class A {
}
Run Code Online (Sandbox Code Playgroud)

这是文件b.php的内容

<?php  // content of b.php
include dirname(__FILE__) . "/a.php";
echo "A: ", class_exists("A") ? "exists" : "doesn’t exist", "\n";
echo "B: ", class_exists("B") ? "exists" : "doesn’t exist", "\n";
echo "BA (before): ", class_exists("BA") ? "exists" : "doesn’t exist", "\n";
echo "BB: ", class_exists("BB") ? "exists" : "doesn’t exist", "\n";
class B {
}
class BA extends A {
}
class BB extends B {
}
echo "BA (after): …
Run Code Online (Sandbox Code Playgroud)

php extends class require include

18
推荐指数
1
解决办法
1789
查看次数