English 中文(简体)
假肢口译员无法找到我的班子?
原标题:Scala interpreter can t find my class?

I m试图在口译人员内装上一个Schala档案:

trait MyOrdered {
  def <(that: MyInt):Boolean = compare(that) < 0
  def >(that: MyInt):Boolean = compare(that) > 0
  def <=(that: MyInt):Boolean = compare(that) < 0 || this == that
  def >=(that: MyInt):Boolean = compare(that) > 0 || this == that
  def compare(that: MyInt): Int
}

class MyInt(val value: Int) extends MyOrdered {
  def compare(that: MyInt) =
    if (this.value < that.value) -1 
    else if (this.value == that.value) 0
    else 1
}


object App extends Application{
  val a = new MyInt(2)
  val b = new MyInt(4)
  println(a < b)
  println(a > b)
}

但是,我有sil误:

Loading traits.scala...
<console>:8: error: not found: type MyInt
         def <(that: MyInt):Boolean = compare(that) < 0
                     ^
<console>:12: error: not found: type MyInt
         def compare(that: MyInt): Int

我怎么能让口译员了解在公路上界定的<代码>MyInt级?

最佳回答

我想请见<代码>:paste。 如同你在口译中打字一样,即一旦发现关闭的图书馆,就立即解释。 页: 1 具体做法是:

object Test {
  trait MyOrdered {
def <(that: MyInt):Boolean = compare(that) < 0
def >(that: MyInt):Boolean = compare(that) > 0
def <=(that: MyInt):Boolean = compare(that) < 0 || this == that
def >=(that: MyInt):Boolean = compare(that) > 0 || this == that
def compare(that: MyInt): Int
}

class MyInt(val value: Int) extends MyOrdered {
  def compare(that: MyInt) =
  if (this.value < that.value) -1 
  else if (this.value == that.value) 0
  else 1
}


object App extends Application{
  val a = new MyInt(2)
  val b = new MyInt(4)
  println(a < b)
  println(a > b)
 }
}

现在,你可以在<条码>后使用这一条:载荷测试:scala和<条码>进口测试>_。

问题回答

暂无回答




相关问题
Having many stacks with different types

I m making a C program that needs to use two stacks. One needs to hold chars, the other needs to hold doubles. I have two structs, node and stack: struct node { double value; struct node *...

Creating (boxed) primitive instance when the class is known

I need a method that returns an instance of the supplied class type. Let s assume that the supplied types are limited to such that an "empty" instance of them can be created. For instance, supplying ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

How to generate an instance of an unknown type at runtime?

i ve got the following in C#: string typename = "System.Int32"; string value = "4"; theses two strings should be taken to generate an object of the specified type with the specified value... result ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

热门标签