Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala A<;:&书信电报;SomeType参数声明_Scala_Function - Fatal编程技术网

Scala A<;:&书信电报;SomeType参数声明

Scala A<;:&书信电报;SomeType参数声明,scala,function,Scala,Function,查看scala.Option[T]sources,我发现以下隐式参数声明implicit ev:Null 我发现p看起来像函数1 它们有不同的语义。在test中,您声明T是选项[Int]的一个子类型。在test2中没有这样的约束 但是如何使用测试?有没有一种方法可以调用它?但是@Kolmar仍然不能使paFunction1。这只意味着约束使用了中缀符号,实际上它被定义为@Dici。深入研究文档时,我发现它的意图只是用作隐式参数要约束方法参数列表中范围内的任何抽象类型T(不仅仅是方法自己的类型参数

查看
scala.Option[T]
sources,我发现以下隐式参数声明
implicit ev:Null
我发现
p
看起来像
函数1


它们有不同的语义。在
test
中,您声明
T
选项[Int]
的一个子类型。在
test2
中没有这样的约束

但是如何使用
测试
?有没有一种方法可以调用它?但是
@Kolmar仍然不能使
p
a
Function1
。这只意味着约束使用了中缀符号,实际上它被定义为
@Dici。深入研究文档时,我发现它的意图只是用作隐式参数
要约束方法参数列表中范围内的任何抽象类型T(不仅仅是方法自己的类型参数),只需添加类型为
T@Dici的隐式参数,但您不能解释是谁创建了这个
隐式,那么如何调用
test2
?我应该传递什么作为参数以使其编译?
class Test[T](val i: Int){
  def test(p: T <:< Option[Int]) = 1
}
class TestMatch[T](val i: Int){
    def test(p: T <:< Option[Int]) =  //..
    def test2(p: T => Option[Int]) =  //...
}
tm.test2(x => { //fine
  println(x)
  Some(x)
})

tm.test(x => { //Compile error
  println(x)
  Some(x)
})
tm.test(x <:< { //Compile error
  println(x)
  Some(x)
})
sealed abstract class <:<[-From, +To] extends (From => To) with Serializable
def greaterThan[T](x: T, y: T)(implicit ev: T <:< Ordered[T]): Boolean = x > y