简体   繁体   English

多个参数化类型是什么意思?

[英]what does more than one Parameterized Types mean?

i'm learning some scala example from somewhere, it looks like as beblow:我正在从某处学习一些 scala 示例,如下所示:

class className[T <: classTypeA : classTypeB](some args)....

or

class className[T<:classTypeA with trait1](some args)...

some tutorial explain that T<:classTypeA means T must be the subclass of classTypeA.一些教程解释说T<:classTypeA意味着 T 必须是 classTypeA 的子类。 i don't understand why there are two types after "<:", and what "with trait1" means;我不明白为什么“<:”之后有两种类型,以及“with trait1”是什么意思;

class className[T <: classTypeA : classTypeB](some args)

In this declaration classTypeB is a type class and this is equivalent to在这个声明中classTypeB是一个类型 class ,这相当于

class className[T <: classTypeA](implicit ev: classTypeB[T])(some args)

There must be a suitable instance of classTypeB[T] in scope for this to compile. scope 中必须有一个合适的classTypeB[T]实例才能编译。 This allows fine-grain control of which types are accepted as parameters to the class.这允许细粒度控制哪些类型被接受为 class 的参数。


class className[T <: classTypeA with trait1](some args)

This declaration says that T must be a subclass of the type classTypeA with trait1 .该声明表明T必须是classTypeA with trait1类型的子类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM