require

def this(name: String, age: Int) = {
this()
require(name != null && !name.isEmpty, "name")
require(age > 0, "illegal age")
Preconditions.checkArgument(name != null && !name.isEmpty, "name required") // 使用 guava 工具类,这行编译不过... 改写为下两种调用方式可通过
// Preconditions.checkArgument(name != null && !name.isEmpty, "name required".asInstanceOf[Any])
// Preconditions.checkArgument(name != null && !name.isEmpty, "name required", null)
setAge(age)
setName(name)
}

什么鬼

  1. require

    • 函数签名: final def require(requirement: Boolean, message: => Any) ,注意第二个参数类型是一个函数
    • 以上栗子中调用了两次 require 函数,生成两个匿名对象...
  2. ambiguous reference to overloaded definition

    • 编译错误信息:

       Error:(44, 21) ambiguous reference to overloaded definition,
      both method checkArgument in object Preconditions of type (x$1: Boolean, x$2: String, x$3: Object*)Unit
      and method checkArgument in object Preconditions of type (x$1: Boolean, x$2: Any)Unit
      match argument types (Boolean,String)
      Preconditions.checkArgument(name != null && !name.isEmpty, "name required")

Scala 槽点 - require的更多相关文章

  1. Scala断言

    断言:提供了一组断言函数以用作在代码中记录和动态检查不变量的方式. import scala.Predef._ def addNaturals(nats: List[Int]): Int = { // ...

  2. Scala函数式对象-有理数

    有理数类的表示 实现规范:支持有理数的加减乘除,并支持有理数的规范表示 1.定义Rational 首先,考虑用户如何使用这个类,我们已经决定使用“Immutable”方式来使用Rational对象,我 ...

  3. Scala实践3

    一.函数式对象 1.1  rational类的规格和创建 Rational类来源于有理数(rational number),来表示n(分子)/d(分母)的数字,同时对有理数的运算(加减乘除)建模,还具 ...

  4. scala编程(六)——函数式对象

    Rational 的式样书 分数:rational number 是一种可以表达为比率 d n 的数字,这里的 n 和 d 是数字,其中 d 不能为零.n 被称作是分子:numerator,d 被称作 ...

  5. 推荐系统那点事 —— 基于Spark MLlib的特征选择

    在机器学习中,一般都会按照下面几个步骤:特征提取.数据预处理.特征选择.模型训练.检验优化.那么特征的选择就很关键了,一般模型最后效果的好坏往往都是跟特征的选择有关系的,因为模型本身的参数并没有太多优 ...

  6. Kafka运维填坑(转)

    前提: 只针对Kafka 0.9.0.1版本; 说是运维,其实偏重于问题解决; 大部分解决方案都是google而来, 我只是作了次搬运工; 有些问题的解决方案未必一定是通用的, 若应用到线上请慎重; ...

  7. IllegalArgumentException: requirement failed: Corrupt index found

    今天突然接到客户反映线上服务器发送消息异常,登录服务器查看是kafka服务出现了问题,想重启一下服务,结果重启出现一下报错 [2017-06-30 19:29:13,708] FATAL Fatal ...

  8. spark-streming 中调用spark-sql时过程遇到的问题

    在spark-streming 中调用spark-sql时过程遇到的问题 使用版本:spark-2.1.0 JDK1.8 1. spark-sql中对limit 的查询结果使用sum() 聚合操作不生 ...

  9. No output operations registered, so nothing to execute

    SparkStreaming和KafKa结合报错!报错之前代码如下: object KafkaWordCount{ val updateFunc = (iter:Iterator[(String,Se ...

随机推荐

  1. loadrunner 快捷键

    lr 不同的界面切换 crt f6lr:选中要查找的内容 ctrl +f3 超找文本 选中所有字母大写 ctl +shift+ u;小写

  2. tp5 之 "No input file specified

    tp5 之 "No input file specified" 问题 通过"域名/模块/控制器/方法"这样的方式访问的时候,浏览器输出如下: 直接通过" ...

  3. htmlspecialchars_decode 解决掉 &

    如果在请求中返回的内容包含 & 请使用htmlspecialchars_decode 搞一下,去掉. 这个纯粹为自己怕到时又找不到这个方法

  4. bootstrap-thymeleaf-分页

    1.HTML代码 <div th:fragment="paginater"> <ul th:id="paginaterUlID" th:if= ...

  5. 2019-8-30-MSBuild-常用参数

    title author date CreateTime categories MSBuild 常用参数 lindexi 2019-8-30 8:56:5 +0800 2019-07-20 21:56 ...

  6. 五、通过密码访问API

    通过密码访问API 一.客户端 图: 客户端请求代码: static void Main(string[] args) { Console.WriteLine("确定三个项目都已经启动&qu ...

  7. Codeforces 1178F DP

    题意:有一张白纸条,你需要给这张纸条染色.染色从颜色1开始染色,每次选择纸条的一段染色时,这一段的颜色必须是相同的.现在给你染色后的纸条,问有多少种染色方案? F1: 思路:最开始的想法是以染色顺序为 ...

  8. 启动数据库报:ORA-03113

    1启动数据库报:ORA-03113 2.查看oracle运行日志 tail  -50 //home/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.l ...

  9. docker 安装 jenkins 笔记

    前提: 已安装好 docker-ce,可运行 docker 命令 命令: sudo docker pull jenkins mkdir -p ~/dockers/jenkins cd ~/docker ...

  10. python 字符串中替换字符

    今天本来打算写个程序,替换字符串中固定的一个字符:将<全部替换成回车'\n' 于是,我写成这样 s='sdjj<ddd<denj,>' for x in s: if x=='& ...