小编Man*_*dha的帖子

无法重写 Scala 中的方法

我有 2 个特质和 1 个职业。

在 Trait 中A,方法A1和实现都A2需要实现

scala> trait A {
     | def A1
     | def A2
     | }
defined trait A
Run Code Online (Sandbox Code Playgroud)

在 Trait 中B,尽管A1在这里实现了,但它需要是抽象的,因为它使用了 super 并且仍然需要在实例类中实现。A2已实施

scala> trait B extends A {
     | abstract override def A1 = {
     | super.A1
     | }
     | def A2 = println("B")
     | }
defined trait B
Run Code Online (Sandbox Code Playgroud)

现在我有一个C定义的类A1(与以前的特征无关)

scala> class C {
     | def A1 = …
Run Code Online (Sandbox Code Playgroud)

scala

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

justify-content and align-content not working in CSS Grid

I have a grid with 3 rows, 1 column and item of the middle row is a grid itself of 2 columns and 4 rows.

CSS Snippet

.css-grid-container-common-styles{
    height:100vh; /*???*/
    display: grid;
    grid-template-columns: 1fr;  /* 1column*/
    grid-template-rows: auto 15fr 1fr; /* 3 rows. Auto takes height of navigation, remaininign is divided into 2 rows, middle row is 15 times larger than the 3rd row.*/
}
Run Code Online (Sandbox Code Playgroud)

HTML Snippet

<div class="css-grid-container-common-styles"> <!-- first container -->
<nav class="navbar navbar-expand-lg navbar-light bg-light css-grid-item-nav-div-common-styles"> <!-- …
Run Code Online (Sandbox Code Playgroud)

css centering flexbox css-grid

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

失败:模块“ DynamicTestModule”导入了意外的指令“ NewPracticeQuestionComponent”。请添加@NgModule批注

我正在对使用其他两个组件的组件进行单元测试。单击按钮时创建其他组件

.html

    <div id="homepage-top-div" class="homepage-component-css-grid-container">  ...
        <button id="get-question-list-button" [routerLink]="questionListRouterLink" class="btn content-div__button--blue css-grid-item-button-div btn-sm">See Questions</button>
      </div>
      <div id="practice-component-top-div" class="css-grid-container-div common-styles-div--white"> <!-- 4 rows, 1 column-->
...
        <button id="new-question-button" [routerLink]="newQuestionRouterLink"  class="btn content-div__button--blue css-grid-item-button-div btn-sm">Create a Question</button>
      </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

.ts

export class HomepageContentComponentComponent implements OnInit {

  public questionListRouterLink="/practice-question-list";
  public newQuestionRouterLink="/new-practice-question";


  constructor() {

  }

  ngOnInit() {
  }

}
Run Code Online (Sandbox Code Playgroud)

我创建了一个,spec但运行时出现以下错误-Failed: Unexpected directive 'NewPracticeQuestionComponent' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation.

规格是

import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; …
Run Code Online (Sandbox Code Playgroud)

angular-testing angular6

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

RouterTestingModule不提供位置的提供程序

我正在Component使用其他两个组件进行单元测试。单击按钮时创建其他组件

.html

    <div id="homepage-top-div" class="homepage-component-css-grid-container">  ...
        <button id="get-question-list-button" [routerLink]="questionListRouterLink" class="btn content-div__button--blue css-grid-item-button-div btn-sm">See Questions</button>
      </div>
      <div id="practice-component-top-div" class="css-grid-container-div common-styles-div--white"> <!-- 4 rows, 1 column-->
...
        <button id="new-question-button" [routerLink]="newQuestionRouterLink"  class="btn content-div__button--blue css-grid-item-button-div btn-sm">Create a Question</button>
      </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

.ts

export class HomepageContentComponentComponent implements OnInit {

  public questionListRouterLink="/practice-question-list";
  public newQuestionRouterLink="/new-practice-question";


  constructor() {

  }

  ngOnInit() {
  }

}
Run Code Online (Sandbox Code Playgroud)

我创建了一个规范,但是运行它时出现以下错误- Error: StaticInjectorError[Location]: NullInjectorError: No provider for Location!

规格是

import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import { HomepageContentComponentComponent } from './homepage-content-component.component';
import …
Run Code Online (Sandbox Code Playgroud)

angular-routing angular angular-testing angular6

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

List中的canEqual对Set参数返回true

问题1 - 当我将List与Set(不同元素)进行比较时,为什么此代码返回true,但当我将List与List或Set of?进行比较时返回false?

scala> val l = List(1,2,3)
l: List[Int] = List(1, 2, 3)

scala> val l2=List(1,2,3)
l2: List[Int] = List(1, 2, 3)

scala> val l3=List(1,3,3)
l3: List[Int] = List(1, 3, 3)

scala> l.canEqual(l2)
res2: Boolean = true

/*I guess this returns true becuase canEqual check for type of the passed instance. Something like def canEqual(other: Any): Boolean = other.isInstanceOf[List] */

scala> l.canEqual(l3)
res3: Boolean = true

//but if canEqual checks for type of passed instance then why this …
Run Code Online (Sandbox Code Playgroud)

scala

0
推荐指数
1
解决办法
122
查看次数

为什么我不能写`List [I]`但是可以写'我'

在下面的代码中,我可以定义idList[I]

abstract trait Repository[I,M] {

    def getOneById(id: List[I]): Option[M]
}
Run Code Online (Sandbox Code Playgroud)

但是,为什么我不能定义idList[I]下面的代码?

abstract trait Repository[List[I],M] {

    def getOneById(id: List[I]): Option[M] //I get compiler error - cannot resolve I. Why?
}
Run Code Online (Sandbox Code Playgroud)

scala

0
推荐指数
1
解决办法
69
查看次数

如何创建对象的自定义toString方法

我想创建toString()以下a对象的自定义方法.但我无法这样做.我读过我应该覆盖prototype.toString但我得到编译错误

 var a = {
    someProperty: 1,
    someotherProperty:3
}

a.prototype.toString = function customPrint(){
    return "the custom print is "+(someProperty+someotherProperty);
}

var b = {
    somePropertyb: 2
}

function printObject(){
    console.log("using , hello: a:",a,"b:",b); //prints using , hello: a: { someProperty: 1, someotherProperty: 3 } b: { somePropertyb: 2 }
    console.log("using + hello: a:"+a+"b:"+b);//prints using + hello: a:[object Object]b:[object Object] if I remove a.prototype.toString code
}

printObject()
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

node print.js print.js:6 a.prototype.toString = function customPrint(){ …

javascript

0
推荐指数
1
解决办法
167
查看次数

有没有办法将匹配与布尔值一起使用

我发现使用matchif. 如果我有一个boolean值,我可以将它与 一起使用match吗?

我通常这样做

if(!authorised) {...} else {..}
Run Code Online (Sandbox Code Playgroud)

但我无法做到

authorised match {
    case ??? //what here??
}
Run Code Online (Sandbox Code Playgroud)

functional-programming if-statement scala pattern-matching

0
推荐指数
1
解决办法
3194
查看次数

错误 CS8803:顶级语句必须位于命名空间和类型声明之前

我不知道如何写c#代码。我试图在这里运行示例代码 - https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/quickstart-dotnet?tabs=azure-portal%2Cwindows%2Cpasswordless%2Csign-in- azure-cli#创建帐户

这是我复制到的代码powershell。当我这样做时dotnet run,我收到错误

/home/manu/Program.cs(24,1): error CS8803: Top-level statements must precede namespace and type declarations. [/home/manu/manu.csproj]

The build failed. Fix the build errors and run again.
Run Code Online (Sandbox Code Playgroud)

代码

// See https://aka.ms/new-console-template for more information
using Microsoft.Azure.Cosmos;
using Azure.Identity;

// New instance of CosmosClient class
using CosmosClient client = new(
    accountEndpoint: Environment.GetEnvironmentVariable("COSMOS_ENDPOINT"),
    tokenCredential: new DefaultAzureCredential()
);


// C# record representing an item in the container
public record Product(
    string id,
    string categoryId,
    string categoryName, …
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
662
查看次数

Scala中的反向滴答用法是什么

我在一本书中找到了以下代码

val list = List(5, 4, 3, 2, 1)
val result = (0 /: list) { (`running total`, `next element`) ?
  `running total` - `next element`
}
Run Code Online (Sandbox Code Playgroud)

反引号用于创建带空格的变量名吗?

scala

-1
推荐指数
1
解决办法
1086
查看次数

传递事件和 $event 之间有区别吗?

如果我通过,则以下 JavaScript 函数有效,event但如果我通过,则会出错$event。两者有什么区别,为什么不起作用$event

function IWasClicked(event) {
    alert("clicked again with event",event);
}
Run Code Online (Sandbox Code Playgroud)

这不起作用,并且$event没有定义给HTMLAnchorElement.onclick

function IWasClicked(event) {
    alert("clicked again with event",event);
}
Run Code Online (Sandbox Code Playgroud)

这有效

<div id="about"><a class="selected-button" href="javascript:void(0)" onclick="IWasClicked($event)">About</a></div>
Run Code Online (Sandbox Code Playgroud)

javascript

-2
推荐指数
1
解决办法
43
查看次数