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", 为避免同名文件覆盖版本号,对替换 ...
随机推荐
- 做SqlDependency总结的一些经验
1.--查询是否具有Broker功能 select is_broker_enabled from sys.databases where [name]='DBName' 2.--打开Broker功能 ...
- Cocos2d-x开发中Ref内存管理
Ref类是Cocos2d-x根类,Cocos2d-x中的很多类都派生自它,例如,我们熟悉的节点类Node也派生自Ref.我们介绍Ref内存管理.内存引用计数Ref类设计来源于Cocos2d-iphon ...
- HDU 2340 Obfuscation(dp)
题意:已知原串(长度为1~1000),它由多个单词组成,每个单词除了首尾字母,其余字母为乱序,且句子中无空格.给定n个互不相同的单词(1 <= n <= 10000),问是否能用这n个单词 ...
- 04_例子讲解:rlViewDemo.exe
参考资料:http://www.roboticslibrary.org/tutorials/first-steps-windows 使用rlViewDemo对应的快捷方式启动程序,可以看到如下界面: ...
- Ubuntu 截屏
一个图说明: 系统设置->键盘->快捷键->屏幕截图 里面可以查看及修改快捷键
- ubuntu修改登录信息(本机和SSH登录)
1.需要修改的主要文件和目录如下:/etc/issue/etc/motd/etc/update-motd.d//etc/issue.net 2.Ubuntu的登陆和欢迎信息控制主要在/etc/issu ...
- 利用cglib生成动态java bean
cglib详细学习 http://blog.csdn.net/u010150082/article/details/10901641 cglib-nodep jar报下载 http://grepcod ...
- 关于canvas中的jquery
关于h5,相比前端的同事们都很了解了吧!h5里面有个canvas,现在用的蛮火.但是canvas里面的代码确实是有点繁多,特别是要对于图形做什么操作的时候...我昨天无意间发现了一个canvas的插件 ...
- 使用GruntJS构建Web程序
Gruntjs是JavaScript项目的构建工具,也是基于node的一个命令行工具.很多开源JS项目都是使用它搭建.如jQuery.Qunit.CanJS等.它有以下作用 合并JS文件 压缩JS文件 ...
- [Linux]学习笔记(3)-uname的用法
uname的用法如下: uname –a[--all]:输出全部信息 [root@linuxforlijiaman ~]# uname -a Linux linuxforlijiaman -.el6. ...