Manifest 与TypeTag
scala> def max[T : Comparator] (a:T, b:T) = { … }
T : Comparator
就表示存在一个 Comparator[T]
类型的隐式值。import scala.reflect.runtime.universe._ def meth[A : TypeTag](xs: List[A]) = typeOf[A] match {
case t if t =:= typeOf[String] => "list of strings"
case t if t <:< typeOf[Foo] => "list of foos"} scala> meth(List("string"))
res67: String = list of strings scala> meth(List(new Foo))
res68: String = list of foos
There exist three different types of TypeTags:
scala.reflect.api.TypeTags#TypeTag
. A full type descriptor of a Scala type. For example, aTypeTag[List[String]]
contains all type information, in this case, of typescala.List[String]
.scala.reflect.ClassTag
. A partial type descriptor of a Scala type. For example, aClassTag[List[String]]
contains only the erased class type information, in this case, of typescala.collection.immutable.List
.ClassTag
s provide access only to the runtime class of a type. Analogous toscala.reflect.ClassManifest
.scala.reflect.api.TypeTags#WeakTypeTag
. A type descriptor for abstract types (see corresponding subsection below).
2. 如何在代码体中获取TypeTag? 当显式使用隐式参数时,可以直接使用这个隐式参数;当使用context bounds时,使用接受相关隐式参数的方法,比如typeOf。
- via the Methods
typeTag
,classTag
, orweakTypeTag
- Using an Implicit Parameter of Type
TypeTag[T]
,ClassTag[T]
, orWeakTypeTag[T]
- Using a Context bound of a Type Parameter
Manifest 与TypeTag的更多相关文章
- scala高级内容(二) - Implicit
一. Implicit关键字 隐士转换 (1)隐士转换函数:用implicit修饰的,只有一个参数的函数.他会被自动执行,来把一个值转换成另一个 class RichFile(val f:File){ ...
- shapeless官方指南翻译写在前面
目录 前言 Shapeless简介 The Type Astronaut's Guide to Shapeless简介 总结 一.前言 在我的2016,感恩.乐观.努力一文中,说2017 ...
- Flink - TypeInformation
Flink 自己创建一套独立的类型系统, 参考, https://ci.apache.org/projects/flink/flink-docs-release-0.10/internals/type ...
- Scala入门到精通——第二十四节 高级类型 (三)
作者:摆摆少年梦 视频地址:http://blog.csdn.net/wsscy2004/article/details/38440247 本节主要内容 Type Specialization Man ...
- Scala 深入浅出实战经典 第46讲: ClassTag 、Manifest、ClasMainifest TagType实战
王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-64讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...
- HTML 5 应用程序缓存manifest
什么是应用程序缓存(Application Cache)? HTML5 引入了应用程序缓存,这意味着 web 应用可进行缓存,并可在没有因特网连接时进行访问. 应用程序缓存为应用带来三个优势: 离线浏 ...
- HTML5之应用缓存---manifest---缓存使用----Web前端manifest缓存
相信来查这一类问题的都是遇到问题或者是初学者吧! 没关系相信你认真看过之后就会知道明白的 这是HTML5新加的特性 HTML5 引入了应用程序缓存,这意味着 web 应用可进行缓存,并可在没有因特网连 ...
- Scala Reflection - Mirrors,ClassTag,TypeTag and WeakTypeTag
反射reflection是程序对自身的检查.验证甚至代码修改功能.反射可以通过它的Reify功能来实时自动构建生成静态的Scala实例如:类(class).方法(method).表达式(express ...
- gulp rev manifest 添加目录前缀
gulp-rev 生成的manifest默认为: "index.css": "index.css?v=04aff97a7b", 为避免同名文件覆盖版本号,对替换 ...
随机推荐
- 人生的抉择—aspx、ashx、asmx文件处理请求效率比较
人生总是面临着许多抉择许多困惑!作为一名"攻城师"或"程序猿"的我们,工作的时候更是如此.你曾经是否苦恼过在系统中使用哪种文件编写客户端请求最合适或最高效呢?a ...
- javascript对象初读
<script type="text/javascript"> function baseClass() { this.showMsg = function() { a ...
- Contest1065 - 第四届“图灵杯”NEUQ-ACM程序设计竞赛(个人赛)B一个简单的问题
题目描述 这是一个三层的字母塔. 如何输出一个任意层数的字母塔呢? 输入 一个数字n(1<=n<=26),表示字母塔的层数 注意 此题多组输入 输出 n层的字母塔 样例输入 3 4 样例 ...
- MQ队列
显示队列名dspmq 打开队列 runmqsc QMSAA 200-远程队列 dis qr(*) 显示所有队列 dis qr(saa_to_cips) all 显示队列参数 20-本地队列 查看队列深 ...
- 表格细边框 并且CSS3加圆角
.YJ table{width:625px;height:860px;text-align:center;overflow:hidden; background:#fff;border-radius: ...
- YII千万级PV架构经验分享--俯瞰篇--业务扩展演变
hello,大家好,我是方少,世上不如意事十有八九吧,即使你感到很满意,也有人感觉太差了,总得感觉我们技术人员都是一个人在战斗,感情却是最深的,一起吃过苦才难忘吧.娇妻艳女,你失意了会和你一起吃苦吗? ...
- 6个好用的Web开发工具
在过去的几年间,涌现出了很多Web开发工具,它们大多还是比较吸引人的,方便了我们的工作.我们可以学习一下这些新东西,短时间就可以拓宽思路(PHP100推荐:学习10分钟,改变你的程序员生涯).这些应用 ...
- c 递归函数浅析
所谓递归,简而言之就是应用程序自身调用自身,以实现层次数据结构的查询和访问. 递归的使用可以使代码更简洁清晰,可读性更好(对于初学者到不见得),但由于递归需要系统堆栈,所以空间消耗要比非递归代码要大很 ...
- stm32之ADC学习
1.stm32中采用的是逐次逼近型模拟数字方式,那么什么是逐次逼近呢? 逐次逼近的方式类似于二分法,以8位数据为例:当输入一个模拟量的时候,首先取这8位数的一半,即1000 0000,与模拟量比较,大 ...
- exec php
$m = memory_get_usage(); echo $m; require_once('include/entryPoint.php'); // for ($i=0; $i < 5000 ...