博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
scala 抽象方法泛型_Scala中的抽象类型与泛型
阅读量:2530 次
发布时间:2019-05-11

本文共 1961 字,大约阅读时间需要 6 分钟。

scala 抽象方法泛型

Scala抽象类型与泛型 (Scala Abstract types vs Generics)

抽象类型 (Abstract type)

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    }

泛型 (Generics)

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

抽象类型和泛型之间的区别 (difference between Abstract types and Generics)

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/

你可能感兴趣的文章
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-6.微信扫码登录回调本地域名映射工具Ngrock...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-8.用户模块开发之保存微信用户信息...
查看>>
Linux下Nginx安装
查看>>
LVM扩容之xfs文件系统
查看>>
Hbase记录-client访问zookeeper大量断开以及参数调优分析(转载)
查看>>
代码片段收集
查看>>
vue-cli3创建项目时报错
查看>>
输入1-53周,输出1-53周的开始时间和结束时间
查看>>
实验二
查看>>
shell——按指定列排序
查看>>
crash 收集
查看>>
507 LOJ 「LibreOJ NOI Round #1」接竹竿
查看>>
UI基础--烟花动画
查看>>
2018. 2.4 Java中集合嵌套集合的练习
查看>>
精通ASP.NET Web程序测试
查看>>
vue 根据不同属性 设置背景
查看>>
51Nod1601 完全图的最小生成树计数 Trie Prufer编码
查看>>
Codeforces 1110D. Jongmah 动态规划
查看>>
android驱动在win10系统上安装的心酸历程
查看>>
优雅的程序员
查看>>