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.ClassTags 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", 为避免同名文件覆盖版本号,对替换 ...
随机推荐
- Android OOM 解决方案
Out of Memory(内存溢出) 几乎是每个Android程序员都会遇到的事.在网上也能找到一大堆的解决方案,之前写过一篇<Android 内存溢出管理与测试>的博文.但感觉写得不是 ...
- Sql server 大全
一.基础 .说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备份数据的 deviceUSE masterEXEC sp_addumpdevice ...
- Agile.Net 组件式开发平台 - 服务器端部署
应用服务器: 操作系统要求推荐Windows Server 2008,服务器硬件如果支持64位建议安装64位操作系统产品以最大化发挥服务器性能. 安装操作系统Windows Server 2008,其 ...
- 文件流操作(FileStream,StreamReader,StreamWriter)
大文件拷贝: /// <summary> /// 大文件拷贝 /// </summary> /// <param name="sSource"> ...
- Swift使用闭包表达式
Swift中的闭包表达式很灵活,其标准语法格式如下:{ (参数列表) ->返回值类型 in 语句组}其中,参数列表与函数中的参数列表形式一样,返回值类型类似于函数中的返回值类型,但不同的是 ...
- (转)SQL按照日、周、月、年统计数据
写sql语句分别按日,星期,月,季度,年统计销售额 --按日 select sum(consume),day([date]) from consume_record where year([date] ...
- java进阶一之jdk8新特性
1.官方发布的jdk8新特性 2.51CTO相关专题
- Qt自定义菜单项
经常会看到一些菜单的部分项是由几个按钮组成的,如酷狗.QQ.360都有类似菜单,对于常规的菜单项,图标 + 文字 实现一个事件,很容易完成,那么怎么自定义菜单项呢? Qt提供了支持,就是利用QWidg ...
- jQuery Mobile里xxx怎么用呀?(集成篇)
jQuery Mobile如何使用GA(Google Analytics)? 什么是GA: http://baike.baidu.com/view/34729.htm http://www.googl ...
- web网页的表单排版利器--960css
表单排版样式 960css 前言 一般web网页的表单排版,大家都习惯用table排版,自己需要根据实际需要去定义TR和TD,很多时候对于TD的高宽度.是否合并行,合并列,都要去做一些处理,这些都是比 ...