本文共 1961 字,大约阅读时间需要 6 分钟。
scala 抽象方法泛型
Abstract types have abstract members i.e. their members do not have the definition or the values. and abstract classes are abstract type variables.
抽象类型具有抽象成员,即其成员没有定义或值。 和抽象类是抽象类型变量。
For example,
例如,
trait trai { type T val variable : T }
Generic classes are those classes that have classes or other types as parameters.
通用类是具有类或其他类型作为参数的那些类。
class division[d]{ def division(u:z, v:z):z =>{ z=u/v; } } // Here, division is a generic that accept type z values
Some points of the difference between Abstract types and Generics in Scala...
Scala中的抽象类型和泛型之间的一些区别...
Abstract type in implement or extended in a Scala Program whereas Generics take a class type as the parameter.
在实现中或在Scala程序中扩展的抽象类型,而泛型则将类类型作为参数。
In Abstract type methods do not have definitions whereas the generics use definition and use other types.
在Abstract类型方法中没有定义,而泛型使用定义并使用其他类型。
Abstract type uses a 'has-a' relation and generics use an 'of' relation.
抽象类型使用“ has-a”关系,泛型使用“ of”关系。
Example of an abstract type, Baleno is a car.
Baleno是一种抽象类型的示例,它是一辆汽车 。
Example of a generic type,
通用类型的示例,
array of maps.
地图数组 。
In Scala, an abstract class or a trait can be abstract type whereas a class that is abstract or simple can be generic if it accepts any type.
在Scala中, 抽象类或特征可以是抽象类型,而抽象类或简单类可以接受任何通用类型。
A class can be abstract as well as generic also, as both concepts can work together as well as individually. You can create a Scala class that generic and abstract as:
一个类既可以是抽象的,也可以是泛型的,因为这两个概念可以一起工作,也可以单独工作。 您可以创建一个通用的和抽象的Scala类:
abstract class product[x] { def product(a:x , b:x ): x }
The method to this class has no definition which means it is abstract and the class uses data of type x which means it is a generic one.
此类的方法没有定义,这意味着它是抽象的,并且该类使用类型为x的数据,这意味着它是通用的。
翻译自:
scala 抽象方法泛型
转载地址:http://lgazd.baihongyu.com/