//object apply_test {
// def main(args:Array[String]): Unit ={
// println("apply 方法:"+apply("zara","gmail.com"))
// println("unapplu方法"+unapply("zara@gmail.com"))
// println("unapply方法"+unapply("zara ali"))
// }
// def apply(user:String,domain:String)={
// user+"@"+domain
// }
// def unapply(str:String):Option[(String,String)]={
// val parts=str split "@"
// if(parts.length==2){
// Some(parts(0),parts(1))
// }else{
// None
// }
// }
//} //编译器在实例化的时会调用 apply 方法
//提取器对象中使用 match 语句是,unapply 将自动执行
object apply_test{
def main(args:Array[String]): Unit ={
val x=apply_test(5)
println(x)
x match{
case apply_test(num) =>println(x+"是"+num+"的2倍")
case _ =>println("无法计算")
}
}
def apply(x:Int)=x*2
def unapply(z:Int):Option[Int]=if(z%2==0) Some(z/2) else None
}

apply_test的更多相关文章

随机推荐

  1. 微信小程序 API 数据缓存

    微信小程序 数据缓存 (类似于 cookie) wx.setStorage() 将数据存储在本地缓存中制定的 key 中.会覆盖掉原来该 key 对应的内容,数据存储生命周期跟小程序本身一致,即除用户 ...

  2. 编译rxtx

    https://blog.csdn.net/github_29989383/article/details/51886234 https://cloud.tencent.com/developer/a ...

  3. shell脚本之case用法

    你会经常发现自己在尝试计算一个变量的值,在一组可能的值中寻找特定值.在这种情形下, 你不得不写出很长的if-then-else语句,就像下面这样. $ cat test25.sh #!/bin/bas ...

  4. ros the public key is not available

    W: An error occurred during the signature verification. The repository is not updated and the previo ...

  5. 在word中的表格指定位置插入一行

    //创建一个Document类对象,并加载Word文档 Document doc = new Document(); doc.LoadFromFile(@"C:\Users\Administ ...

  6. 阶段3 1.Mybatis_03.自定义Mybatis框架_7.自定义Mybatis的编码-实现基于注解配置的查询所有

    注解的方式,这里进行修改.上面注释的是原来xml的方式. 在dao类里面加上注解 创建注解类 声明注解的生命周期为Runntime 改变注解出现的位置,在Mehtod方法上 写完之后这里就不报错了. ...

  7. 用apicloud+vue的VueLazyload实现缓存图片懒加载

    <script src="../../script/vue-lazyload.js"></script><img v-lazy="remot ...

  8. windows 开启/关闭本地连接的批处理程序

    ::命令前加@符号,表示不显示@后面的命令. @echo off title Open / Close Network ::本地网络适配器名称 set name=以太网 ::查看网络状态,后反向设定 ...

  9. 刘铁猛-深入浅出WPF-系列资源汇总

    首先奉上原作者刘铁猛博客地址:http://www.cnblogs.com/prism/ 作者讲的很不错,没有之一,另外作者出了一本书,希望大家支持. 送上全套高清晰视频教程(我注册了3个51cto的 ...

  10. 发布项目到github上web服务器来运行

    $ git add dist Administrator@LuoTong- MINGW32 /D/react_workspace (master) $ git commit -m "git ...