黑客教程练习16的正确答案是什么?
教程链接:哈克郎教程
修改后的代码(未标记为解决方案):
<?hh
// The type 'this' always points to the most derived type
class MyBaseClass {
protected int $count = 0;
public function add1(): this {
$this->count += 1;
return $this;
}
}
class MyDerivedClass extends MyBaseClass {
public function print_count(): void { echo $this->count; }
}
function test(): void {
$x = new MyDerivedClass();
$x->add1()->print_count();
}我用MyBaseClass代替了this,但仍然没有标记为正确(绿色文本加上练习号)。什么是正确答案?
发布于 2014-03-24 15:48:34
我是一名工程师,在Hack工作。我非常肯定,在本教程中,本练习的完成检测逻辑中存在一个bug。在我看来,您的代码是正确的--据我所见,将返回类型更改为this是您应该做的一切。我会跟进并修复这个窃听器。真对不起!
https://stackoverflow.com/questions/22609690
复制相似问题