ITPub博客

首页 > 应用开发 > IT综合 > scala class和object的区别

scala class和object的区别

原创 IT综合 作者:破棉袄 时间:2015-10-21 09:25:34 0 删除 编辑

Scala中类对象中不可有静态变量和静态方法,但是提供了“伴侣对象”的功能:在和类的同一个文件中定义同名的Object对象:(须在同一文件中;main方法定义在Object对象中)

  1. private[spark] class Client(
  2.     val args: ClientArguments,
  3.     val hadoopConf: Configuration,
  4.     val sparkConf: SparkConf)
  5.   extends Logging {...}

  6. object Client extends Logging {
  7.   def main(argStrings: Array[String]) {
  8.     if (!sys.props.contains("SPARK_SUBMIT")) {
  9.       logWarning("WARNING: This client is deprecated and will be removed in a " +
  10.         "future version of Spark. Use ./bin/spark-submit with \"--master yarn\"")
  11.     }

  12.     // Set an env variable indicating we are running in YARN mode.
  13.     // Note that any env variable with the SPARK_ prefix gets propagated to all (remote) processes
  14.     System.setProperty("SPARK_YARN_MODE", "true")
  15.     val sparkConf = new SparkConf

  16.     val args = new ClientArguments(argStrings, sparkConf)
  17.     // to maintain backwards-compatibility
  18.     if (!Utils.isDynamicAllocationEnabled(sparkConf)) {
  19.       sparkConf.setIfMissing("spark.executor.instances", args.numExecutors.toString)
  20.     }
  21.     new Client(args, sparkConf).run()
  22.   }
  23.  ......
  24. }


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29754888/viewspace-1815301/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-07-16

  • 博文量
    180
  • 访问量
    1111232