Predef

Scala implicitly imports members of packages java.lang and scala , as well as the members of a singleton object named Predef , into every Scala source file. Predef , which resides in package scala , contains many useful methods. For example, when you say println in a Scala source file, you’re actually invoking println on Predef . ( Predef.println turns around and invokes Console.println , which does the real work.) When you say assert , you’re invoking Predef.assert .

From [Pgrogramming in Scala, 2nd Edition, Page 113]

require

Partioner.scala require

class RangePartitioner[K : Ordering : ClassTag, V](
    @transient partitions: Int,
    @transient rdd: RDD[_ <: Product2[K,V]],
    private var ascending: Boolean = true)
  extends Partitioner {

  // We allow partitions = 0, which happens when sorting an empty RDD under the default settings.
  require(partitions >= 0, s"Number of partitions cannot be negative but found $partitions.")

Predef.scala

/** Tests an expression, throwing an `IllegalArgumentException` if false.
   *  This method is similar to `assert`, but blames the caller of the method
   *  for violating the condition.
   *
   *  @param requirement   the expression to test
   *  @param message       a String to include in the failure message
   */
  @inline final def require(requirement: Boolean, message: => Any) {
    if (!requirement)
      throw new IllegalArgumentException("requirement failed: "+ message)
  }

require的方法定义 message: => Any 意思是中间这一段是代码,Any是返回值 上面s"Number ..."就是一个表达式,返回的是String StringContext.scala的定义

def s(args: Any*): String = standardInterpolator(treatEscapes, args)

=> SomeType means

这种叫call-by-name 如果是直接的参数则先计算,这样是后计算,即用到这个变量才计算 也就是说RagePartioner里require的条件不满足是才会产生需要输出的字符串

参见pass-by-name

???

def ??? : Nothing = throw new NotImplementedError
// CheckpointRDD
protected override def getPartitions: Array[Partition] = ???

用来表示TODO或者要 必须? 完成的 参见 What does '???' (three question marks) mean in Scala?

results matching ""

    No results matching ""