println("Step 1: How to create a wrapper String class which will extend the String type")
class DonutString(s: String) { def isFavoriteDonut: Boolean = s == "Glazed Donut" } println("\nStep 2: How to create an implicit function to convert a String to the wrapper String class")
object DonutConverstions {
implicit def stringToDonutString(s: String) = new DonutString(s)
} println("\nStep 3: How to import the String conversion so that it is in scope")
import DonutConverstions._ println("\nStep 4: How to create String values")
val glazedDonut = "Glazed Donut"
val vanillaDonut = "Vanilla Donut" println("\nStep 5: How to access the custom String function called isFavaoriteDonut")
println(s"Is Glazed Donut my favorite Donut = ${glazedDonut.isFavoriteDonut}")
println(s"Is Vanilla Donut my favorite Donut = ${vanillaDonut.isFavoriteDonut}")

result

Step 1: How to create a wrapper String class which will extend the String type

Step 2: How to create an implicit function to convert a String to the wrapper String class

Step 3: How to import the String conversion so that it is in scope

Step 4: How to create String values

Step 5: How to access the custom String function called isFavaoriteDonut
Is Glazed Donut my favorite Donut = true
Is Vanilla Donut my favorite Donut = false

  

最新文章

  1. linux搭载discuz
  2. DFD数据流程图
  3. 剑指offer系列40----机器人的运动范围
  4. java常见面试题
  5. hdu 3966 Aragorn's Story(树链剖分+树状数组)
  6. GBDT详解
  7. 使用imageLoader加载图片资源
  8. how tomcat works 六 生命周期
  9. MongoDB常用配置项目
  10. 展开被 SpringBoot 玩的日子 《 三 》 整合Redis
  11. Java基础12:深入理解Class类和Object类
  12. 测者的测试技术手册:自动的自动化框架EvoSuite集成Cobertura得到可视化的代码覆盖报告
  13. java Reference
  14. 13 Tensorflow API主要功能
  15. forfiles命令详解
  16. 社交网络编程API之iOS系统自带分享
  17. Lab 1-1
  18. 转 linux 权限
  19. 四、curator recipes之共享重入互斥锁
  20. [ldap]ldap server安装以及图形化操作

热门文章

  1. PAT甲级题分类汇编——线性
  2. C++ new/delete详解及原理
  3. ALV报表——基础(一)
  4. VS.NET(C#)--2.3良构的XHTML
  5. centos7.x安装docker-ce
  6. 【日语】日语能力考试N2级核心词汇必备—接续词
  7. py-2 python介绍与安装
  8. 【robotframework】robotframework基本使用
  9. xshell退出保持后台服务运行的方法
  10. Java基本知识点o(1), o(n), o(logn), o(nlogn)的了解