小编nz_*_*_21的帖子

如何调试和修复发散隐式

我是 Scala 的初学者,我正试图将我的头脑围绕在发散的隐式扩展上。

这是我的玩具代码:


class FooList[T](implicit ord: Ordering[T]) {

}

class Human(val score: Int) extends Ordering[Human] {


  override def compare(x: Human, y: Human): Int = {
    return x.score.compareTo(y.score);  
  }
}


object Main {

  def main(args: Array[String]): Unit = {
    val h = new Human(100)
    val lst = new FooList[Human]();
  }
}

Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

diverging implicit expansion for type Ordering[Human]
starting with method comparatorToOrdering in trait LowPriorityOrderingImplicits


not enough arguments for constructor FooList: (implicit ord: Ordering[Human])FooList[Human].
Unspecified value parameter ord.

Run Code Online (Sandbox Code Playgroud)

https://scastie.scala-lang.org/wkSrZ6BMQKW9ZJrsZhlITQ

我希望在正确的方向上有一两个指针:)

scala implicit

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

Android视图永远不会消失

我试图提出一些看法。这是XML代码:


<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">


    <Button
            android:text="See More Like This"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/recommender"
            tools:visibility="invisible"
            android:layout_marginEnd="24dp" android:layout_marginRight="24dp" android:layout_marginBottom="20dp"
            app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toTopOf="@+id/imageView"/>
    <TextView
            android:text="https://www.google.com"
            android:layout_width="169dp"
            android:layout_height="50dp"
            android:autoLink="web"
            android:linksClickable="true"
            android:id="@+id/urlDisplay"
            tools:visibility="invisible"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
            android:layout_marginLeft="24dp" android:layout_marginTop="101dp" android:layout_marginStart="24dp"/>

    <TextView
            android:text="TextView"
            android:layout_width="0dp"
            android:layout_height="59dp"
            android:id="@+id/comicTitle" tools:visibility="invisible"
            android:layout_marginTop="21dp" android:layout_marginBottom="21dp" app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toTopOf="@+id/urlDisplay" app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="40dp"
            android:layout_marginStart="40dp" android:layout_marginEnd="40dp" android:layout_marginRight="40dp"/>

</android.support.constraint.ConstraintLayout>

Run Code Online (Sandbox Code Playgroud)

除了样板外,没有Kotlin代码。启动应用程序时,所有视图都是可见的。考虑到我已将它们明确设置为在xml中不可见,所以我不知道这是怎么发生的。

如何使它们不可见?

xml android view

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

Kotlin: How to invoke super after some computation?

At present, I have a custom error defined like so:

class IsEvenError(message:String):Exception(message)

val n = 10;
if (n%2 == 0) {
   throw IsEvenError("${n} is even");
}

Run Code Online (Sandbox Code Playgroud)

The problem with this is, I have to manually write out the error message every time I want to throw it.

I want to be able to embed the error message into the class itself, so I can do something like:

throw IsEvenError(n); // this should throw an error saying "10 is even".

Run Code Online (Sandbox Code Playgroud)

How …

error-handling kotlin

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

Kotlin无法通过反射访问委托的方法:“ java.lang.NoSuchMethodException”

我试图了解反思如何与委派一起工作,并且提出了一个玩具示例。


class Foo(val m: MutableList<Any>) : MutableList<Any> by m{
}



fun fooAdd(f: Foo) {
    val a = f::class.java.getMethod("add").invoke(f, 20);
    println(a)
}

fun main(args: Array<String>) {
    fooAdd(Foo(mutableListOf()))
}
Run Code Online (Sandbox Code Playgroud)

这给我一个错误:

Exception in thread "main" java.lang.NoSuchMethodException: Foo.add()
Run Code Online (Sandbox Code Playgroud)

我不知道我理解为什么它的发生,看到 add()被委派给FooMutableList如果我理解正确。

如何解决此错误?另外,是否有一个应该用于这种用例的库?

reflection delegation kotlin

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

如何将边界框与 groupRectangle 合并?

我有一个带有边界框的图像,如下所示:

在此处输入图片说明

我想合并重叠的边界框。

我试过: cv::groupRectangles(detected, 1, 0.8)

我的期望是每个集群都有一个盒子。

但我得到了这个:

在此处输入图片说明

正如你所看到的,问题是,中间的飞镖板和右边的飞镖板没有盒子

我该如何解决?我更喜欢使用 OpenCV api 而不是编码我自己的合并算法。

我看到它消除了恰好由一个盒子包围的区域。我希望它不要那样做。

我曾尝试随机调整参数,但结果更糟。我希望得到一些正确方向的指导。

c++ opencv image-processing

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

python3中自动关闭文件?

我的想法是否正确,这会自动关闭文件?

def get_file():
    with open("file.csv", "rb") as f:
        yield f

f = get_file()
do_stuff(f)
Run Code Online (Sandbox Code Playgroud)

如果没有,我如何编写一个返回文件对象的函数,同时确保它在接收器使用完文件后关闭该文件?

python yield file with-statement python-3.x

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

无法使用 delve:pacakge main 不在 GOROOT 中

这是我的目录结构:

\n
root\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 LICENSE\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 README.md\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 acceptor.go\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 cmd\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.go\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 go.mod\n\n
Run Code Online (Sandbox Code Playgroud)\n

我想调试一下cmd/main

\n

我试过: dlv debug main

\n

我收到一个错误:

\n
package main is not in GOROOT (/usr/local/Cellar/go/1.15.5/libexec/src/main)\nexit status 1\n
Run Code Online (Sandbox Code Playgroud)\n

如何解决这个问题?

\n

go delve

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