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. Cocos2d-x之Map<K, V>

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. Map<K, V>是Cocos2d-x 3.0x中推出的字典容器,它也能容纳Ref类型.Map<K,V>是模仿C+ ...

  2. NOIP2015D1T2 信息传递

    题目描述 有 n 个同学(编号为 1 到 n )正在玩一个信息传递的游戏.在游戏里每人都有一个固定的信息传递对象,其中,编号为 i 的同学的信息传递对象是编号为 Ti​ 的同学. 游戏开始时,每人都只 ...

  3. FTP上传下载文件(函数简易版)

    FTP上传下载文件(函数简易版) # 服务端 import socket import json import hashlib import struct import os user_dic = { ...

  4. 好用的打包工具webpack

    <什么是webpack> webpack是一个模块打包器,任何静态资源(js.css.图片等)都可以视作模块,然后模块之间也可以相互依赖,通过webpack对模块进行处理后,可以打包成我们 ...

  5. 52.Product of Array Except Self(除过自身的数组乘积)

    Level:   Medium 题目描述: Given an array nums of n integers where n > 1, return an array output such ...

  6. send, sendto, sendmsg - 从套接字发送消息

    概述 #include <sys/types.h> #include <sys/socket.h> int send(int s, const void *msg, size_ ...

  7. Linux系统分辨率设置

    linux 设置分辨率 如果你需要在linux上设置显示屏的分辨率,分两种情况:分辨率模式存在与分辨率模式不存在,具体如下. 1,分辨率模式已存在 1)如何查询是否存在: 图形界面:在System S ...

  8. shell input value from console

    echo "Please enter some input: " read input_variable echo "You entered: $input_variab ...

  9. Kotlin之let,apply,with,run函数区别(转)

    转自:https://blog.csdn.net/guijiaoba/article/details/54615036 Kotlin之let,apply,with,run函数区别 重新整理 重新整理了 ...

  10. 人脸识别课件需要安装的python模块

    Python3.6安装face_recognition人脸识别库 https://www.jianshu.com/p/8296f2aac1aa