Scala 中的枚举

【Scala面向对象】35、Enumeration枚举类 在 Scala 中,没有像 Java 那样原生的枚举类型,但是可以通过EnumName是枚举类的名称,通常按照 Scala 的命名规范使用首字母大写的形式。是 Scala 内置的枚举类对象,用于定义枚举成员。是枚举类的成员,用于表示一组常量值。每个枚举成员都是Value的实例。每个枚举成员默认的值是Value的实例,其顺序由定义的顺序决定,从 0 开始。在上述示例中,我们为枚举成员和分别指定了值 1、2 和 3。在使用枚举类时,可以通过。 阅读详情

Scala中的枚举

Scala不用关注枚举的特别语法,取而代之的是标准库中的类:scala.Enumeration

object Main extends App {

  object WeekDay extends Enumeration {
    type WeekDay = Value//这里仅仅是为了将Enumration.Value的类型暴露出来给外界使用而已
    val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value//在这里定义具体的枚举实例
  }
  import WeekDay._

  def isWorkingDay(d: WeekDay) = ! (d == Sat || d == Sun)

  WeekDay.values filter isWorkingDay foreach println//使用语法糖进行输出
}

上述是源码中给的一个枚举Example,可以发现:

  • 它是一个伴随对象
  • 需要显式得继承Enumeration
  • 具体的枚举实例都是需要赋值成Value这个对象(它是在超类中定义)

Enumeration源码分析

构造函数以有变量

/** Defines a finite set of values specific to the enumeration. Typically
 *  these values enumerate all possible forms something can take and provide
 *  a lightweight alternative to case classes.
 *
 *  Each call to a `Value` method adds a new unique value to the enumeration.
 *  To be accessible, these values are usually defined as `val` members of
 *  the evaluation.
 *
 *  All values in an enumeration share a common, unique type defined as the
 *  `Value` type member of the enumeration (`Value` selected on the stable
 *  identifier path of the enumeration instance).
 *
 *  @param initial The initial value from which to count the integers that
 *                 identifies values at run-time.
 *  @author  Matthias Zenger
 */
@SerialVersionUID(8476000850333817230L)
abstract class Enumeration (initial: Int) extends Serializable {
  thisenum =>

  def this() = this(0)

    /** The mapping from the integer used to identify values to the actual
    * values. */
  private val vmap: mutable.Map[Int, Value] = new mutable.HashMap

  /** The cache listing all values of this enumeration. */
  @transient private var vset: ValueSet = null
  @transient @volatile private var vsetDefined = false

  /** The mapping from the integer used to identify values to their
    * names. */
  private val nmap: mutable.Map[Int, String] = new mutable.HashMap

  /** The values of this enumeration as a set.
   */
  def values: ValueSet = {
    if (!vsetDefined) {
      vset = (ValueSet.newBuilder ++= vmap.values).result()
      vsetDefined = true
    }
    vset
  }

  /** The integer to use to identify the next created value. */
  protected var nextId: Int = initial

  /** The string to use to name the next created value. */
  protected var nextName: Iterator[String] = _

  private def nextNameOrNull =
    if (nextName != null && nextName.hasNext) nextName.next else null

  /** The highest integer amongst those used to identify values in this
    * enumeration. */
  private var topId = initial

  /** The lowest integer amongst those used to identify values in this
    * enumeration, but no higher than 0. */
  private var bottomId = if(initial < 0) initial else 0

  /** The one higher than the highest integer amongst those used to identify
    *  values in this enumeration. */
  final def maxId = topId

上面是洋洋洒洒贴了Enumeration类在Scala中的部分源码,从中大致可以看到这么几个关键点:

  • 它提供了一个轻量级的枚举类
  • initial初始化变量为整个枚举实例的容量,但是它在运行时可以变化
  • vmap:非常重要的一个变量,它是存储了枚举id和枚举值之间的映射容器。
  • nmap:也是蛮重要的一个变量,存储了枚举id和枚举名称的容器
  • **Id:所有带Id后缀的变量都是为了维护整个枚举的序号
  • 其他就是提供了各种迭代器,用于取值的东西

Value类的相关定义

/** The type of the enumerated values. */
@SerialVersionUID(7091335633555234129L)
abstract class Value extends Ordered[Value] with Serializable {
/** the id and bit location of this enumeration value */
def id: Int
/** a marker so we can tell whose values belong to whom come reflective-naming time */
private[Enumeration] val outerEnum = thisenum

override def compare(that: Value): Int =
  if (this.id < that.id) -1
  else if (this.id == that.id) 0
  else 1
override def equals(other: Any) = other match {
  case that: Enumeration#Value  => (outerEnum eq that.outerEnum) && (id == that.id)
  case _                        => false
}
override def hashCode: Int = id.##

/** Create a ValueSet which contains this value and another one */
def + (v: Value) = ValueSet(this, v)
}

在源码的Example中可以看到所有的枚举都是被赋值为Value类型,从上面的源码中可以看到Value类是一个抽象类,看它的内容只是提供了枚举值比较以及id的获取,在Enumeration源码中提供了一个叫Val的类对Value实现,重要是重写了整数命名和id的识别。

/** A class implementing the [[scala.Enumeration.Value]] type. This class
*  can be overridden to change the enumeration's naming and integer
*  identification behaviour.
*/
@SerialVersionUID(0 - 3501153230598116017L)
protected class Val(i: Int, name: String) extends Value with Serializable {
def this(i: Int)       = this(i, nextNameOrNull)
def this(name: String) = this(nextId, name)
def this()             = this(nextId)
//to do many things.
}

Value方法的定义

请注意,请注意,Example中的第4行、第5行的Value,前者是类,后者是方法(括号省略了而已)

/** Creates a fresh value, part of this enumeration. */
protected final def Value: Value = Value(nextId)

/** Creates a fresh value, part of this enumeration, identified by the
*  integer `i`.
*
*  @param i An integer that identifies this value at run-time. It must be
*           unique amongst all values of the enumeration.
*  @return  Fresh value identified by `i`.
*/
protected final def Value(i: Int): Value = Value(i, nextNameOrNull)

/** Creates a fresh value, part of this enumeration, called `name`.
*
*  @param name A human-readable name for that value.
*  @return  Fresh value called `name`.
*/
protected final def Value(name: String): Value = Value(nextId, name)

/** Creates a fresh value, part of this enumeration, called `name`
*  and identified by the integer `i`.
*
* @param i    An integer that identifies this value at run-time. It must be
*             unique amongst all values of the enumeration.
* @param name A human-readable name for that value.
* @return     Fresh value with the provided identifier `i` and name `name`.
*/
protected final def Value(i: Int, name: String): Value = new Val(i, name)

上面提供了各种Value的重载方法均是返回了Val类,所以说嘛,你有需要完全可以自己再实现一个Value类。

Scala中枚举的简单使用

println(WeekDay.Wed)//直接取枚举值
println(WeekDay.Wed.id)//取枚举值所在序号
println(WeekDay.maxId)//枚举值的个数
println(WeekDay.withName("Wed"))//通过字符串获取枚举(这里是不需要反射的)

获取枚举的具体信息还是非常方便的

Wed
2
7
Wed

获取全部的枚举值进行输出

WeekDay.values.foreach(println(_))
Mon
Tue
Wed
Thu
Fri
Sat
Sun

枚举也可以用在匹配

matchTest(WeekDay.Wed)
matchTest(WeekDay.Sat)

def matchTest=(week:WeekDay.Value) =>week match{//注意,这里枚举的类型都是Value
case w if w.compare(WeekDay.Fri)<=0 =>println("sorry,please working")
case WeekDay.Sat=>println(("go shopping"))
case WeekDay.Sun=>println(("sleeping"))
}

可以看到输出

sorry,please working
go shopping

这里的枚举值的比较其实就是对比他们的Id是否相等。

总结

  • Java中的那套枚举并不能直接使用到Scala中
  • Scala中的枚举使用轻量级Enumeration进行实现
  • Scala中的枚举其实是一个伴随对象
  • Scala中的枚举没有方法重写功能
  • Scala中的枚举其实都是Enumeration.Value这个对象

参考

http://www.cnblogs.com/gnivor/p/4191017.html
Enumeration.scala

原文

https://toutiao.io/posts/g9ktuv/preview

scala-enum:基于密封类的 Scala 枚举的简单 40 行实现 标量枚举 这是基于密封类(支持模式匹配耗尽检查)的枚举的简单 40 行实现。 它使用反射,因此如果您使用它,您可能需要将libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaV到您的项目中。 对象的枚举 定义 sealed abstract class Color ( red : Double , green : Double , blue : Double ) object Color extends EnumOf [ Color ] { case object Red extends Color ( 1 , 0 , 0 ) case object Green extends Color ( 0 , 1 , 0 ) case object Blue extends Color ( 0 , 0 立即下载

相关推荐

Zemax实战:手把手教你设计一个40倍、NA0.65的显微物镜(附初始结构文件)

本文详细介绍了使用Zemax设计40倍、NA0.65显微物镜的完整流程,从初始结构搭建到优化验证,涵盖光学设计的关键技巧和实战经验。通过分阶段优化策略和公差分析,帮助工程师快速掌握高倍显微物镜的设计方法,提升光学系统性能。

weixin_42525369的博客 344

scala中的枚举

1.scala枚举原理 严格来说,和其它语言不同,Scala 并没有枚举这种类型。Scala 中的枚举值只是Enumeration下的Value类的实例,而不是枚举自身的实例。Value类的实例主要依靠其构造方法的两个值:id与name来构建。其中,id是自增长,name如果不指定时默认使用的就是值的名字。所以不像其它语言,Scala 并不能任意定义构造方法来构造枚举。 abstract clas...

bitcarmanlee的博客 3581

高速DAC时钟与配置实战:DAC5681Z硬件设计与寄存器编程详解

在高速数据转换系统中,时钟信号是决定系统性能的核心要素,其稳定性和纯净度直接影响数模转换器(DAC)的输出频谱纯度与动态范围。时钟电路的设计原理涉及信号完整性、阻抗匹配与直流偏置,而内部锁相环(PLL)和延迟锁相环(DLL)的配置则是实现精确时序控制的关键技术。这些技术的价值在于,它们共同保障了高速通信、雷达和任意波形生成等应用对信号实时性与精度的严苛要求。本文聚焦于德州仪器(TI)的DAC5681Z,深入解析其外部时钟输入电路的硬件设计要点,包括端接电阻的计算与选型,并详细拆解通过串行外设接口(SPI)对

weixin_30342363的博客 186

Scala里面如何使用枚举

枚举通常用来定义已知数量的常量,比如月份,星期,季节等等,用过java的人都知道定义枚举的关键字是enum,在scala里面和java有所不同,来看一个完整的例子定义: object EnumTest { /*** * 定义一个星期的枚举 */ object WeekDay extends Enumeration{ type WeekDay = Value /

三劫散仙 2万+

【Flink】FlinkSQL如何触发执行计算

Table (通过 StatementSet.addInsert() 输出给某个 Sink)和 INSERT 语句 (通过调用 StatementSet.addInsertSql())会先被缓存到 StatementSet 中,StatementSet.execute() 方法被调用时,所有的 sink 会被优化成一张有向无环图。该方法是用来将一个表的内容插入到目标表中,一旦该方法被调用, TABLE API 程序立即被翻译。该方法是用来执行一个 SQL 语句,一旦该方法被调用, SQL 语句立即被翻译。

一杯咖啡半杯糖的博客 1007

Linux性能调优之CPU时间分布(亲和性、带宽、权重)配置

带宽权重亲和性进程级别Cgroup-v2服务级别systyemd我所渴求的,無非是將心中脫穎語出的本性付諸生活,為何竟如此艱難呢 ------赫尔曼·黑塞《德米安》

山河已无恙 1714

Scala 枚举的使用和探索(译)

面试:你懂什么是分布式系统吗?Redis分布式锁都不会?>>> ...

Viking的博客 458

北斗导航 | 接收机自主完好性监测与神经网络结合的技术路径、应用场景及研究进展

2] 许承东, 黄国限, 钟贤发, 等. 一种用于神经网络RAIM的故障卫星识别方法[P]. 中国专利: CN117192573A, 2023-12-08.随着6G通信与低轨卫星星座的融合发展,神经网络RAIM有望在2025-2030年实现从辅助技术向主导技术的跨越,成为智能导航系统的核心支撑技术。该架构采用改进型BP神经网络实现非线性映射,在GPS/北斗双模系统中实现98.7%的故障识别率[2]。注:测试条件为GPS/北斗双模系统,12颗可见卫星,含3颗故障卫星的复合场景。

尘世冰封的专栏 481

scala 中的枚举类型

Scala中的枚举 枚举在编程中指的是命名的常量,在scala中提供了一个Enumeration类,我们可以扩展它以创建枚举。 在scala中声明枚举 object Main extends Enumeration { type Main = Value // 赋值 val first = Value("惊悚片") val second = Value("恐怖片") va...

wangrui1605的博客 1563

华为OD机考真题 新系统 - 小菊的寻宝之旅(Java/Py/C/C++/Js/Go)

华为OD机试真题 新系统【小菊的寻宝之旅】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题 【小菊的寻宝之旅】多语言题解。

qq_45776114的博客 622

[Dify] -进阶13- 使用“知识库 + 工作流”打造智能推荐系统

本文介绍了在Dify平台上构建智能推荐系统的方法,重点阐述了知识库与工作流技术的结合应用。通过知识库管理RAG流程,实现文档上传、向量嵌入和检索优化;利用工作流设计节点化推荐逻辑,支持并行处理与条件分支。以电话销售话术推荐为例,展示了从数据收集到实时生成的完整流程。该方法具有准确性高、扩展性强、维护简便等优势,可广泛应用于各类推荐场景,实现从数据存储到智能推荐的闭环解决方案。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 1067

Scala枚举

Scala定义枚举类,需要扩展类对象为scala.Enumeration。 定义 // 1 object DeployMode extends Enumeration { val LOCAL,TEST,PRODUCTION = Value } // 2 object DeployMode extends Enumeration { val LOCAL = Value v...

L, there! 448

5. SAP UI5 视图控制器(Controller)初探

本教程的前一个步骤也就是第四个步骤,我们了解了 SAP UI5 XML 视图的使用方法。在该步骤里,我们在 XML 视图里声明了一个 Text 控件实例,该控件位于 sap.m 这个命名空间内。 本步骤会继续接触 SAP UI5 MVC 框架中三大基石的另一块:C - Controller,即控制器。 先看看本步骤完成之后,我们得到的 SAP UI5 应用能实现一个什么样的效果。 访问如下 url: http://localhost:8080/webapp/index.html 能看到一个 Say Hell

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 4598

java调用scala枚举_Scala中的枚举

与java不同,scala并没有提供枚举类型,而是通过Enumeration类的帮助来实现枚举功能的。object SourceType extends Enumeration{//这行是可选的,类型别名,在使用import语句的时候比较方便,建议加上type SourceType = Value//枚举的定义val Kafka, Avro, Custom = Value}使用方法def load...

weixin_28973031的博客 317

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

枚举scala

case d if d == Stars.地球 || d == Stars.火星 => println(s"适合人类居住的星球 = $d")val 地球 = Value(-1, "地球是最美丽的蔚蓝色")val 火星 = Value(4, "火星是火红颜色的")val 金星 = Value(0, "金星是金色的")val 地球 = Value("地球是最美丽的蔚蓝色")val 火星 = Value("火星是火红颜色的")val 金星 = Value("金星是金色的")

2403_87257611的博客 540

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

java调用scala枚举_Scala里面如何使用枚举

枚举通常用来定义已知数量的常量,比如月份,星期,季节等等,用过java的人都知道定义枚举的关键字是enum,在scala里面和java有所不同,来看一个完整的例子定义:object EnumTest {/**** 定义一个星期的枚举*/object WeekDay extends Enumeration{type WeekDay = Value //声明枚举对外暴露的变量类型val Mon = ...

weixin_32296621的博客 293

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

[Scala基础]--Scala枚举使用

参考:http://www.scala-lang.org/api/current/scala/Enumeration.htmlhttp://www.jianshu.com/p/675dad38c8a6http://xiaoxin2009.github.io/Scala%E7%B1%BB%EF%BC%8C%E5%AF%B9%E8%B1%A1.htmlScala的枚举与java/c++不同,scala...

欢迎来到我的博客,一起探索代码里的世界! 2647

Scala Enumerate (枚举)

Enumerate (枚举)在Scala中,没有语言级别的枚举类型,枚举的功能可以通过继承枚举类Enumeration实现。继承枚举类继承枚举类Enumeration可以在成员中使用无参方法Value给每个枚举成员赋值。

言の叶の庭 6233

java调用scala枚举,在Scala中创建Java枚举

My workplace has been experimenting in moving from Java to Scala for some tasks, and it works well for what we're doing. However, some preexisting logging methods expect a java.lang.Enum. The logging ...

weixin_39601088的博客 186

Scala_Scala类 =》 枚举类

         Scala  中的 枚举类比较有用, 又和Java 不太一样,我们在这里整理一下。 枚举主要用于 表述语义更为清楚,例如,以下两个 变量 : ”7“  与  MediaCode.SOHU, 肯定是 Media.SOHU 更容易被理解。   目录 1.基础案例 2.语法介绍 3.扩展函数         1.基础案例   基础的枚举, 示例如下: p...

迎难而上 2636

Scala中的枚举类型

Scala中的枚举类型说明 说明 在Scala的Enumeration类中定义了一个名为Value的内部类,跟这个内部类同名的不带参数的Value方法每次都返回这个类的全新实例。也可以用重载Value的方法给枚举值关联特定的名称,如下代码 定义枚举类. package com.mc.enum object GenderEnum extends Enumeration { type Gen...

剁椒鱼不要头的博客 1431

谈谈Scala中的枚举

http://kubicode.me/2015/06/06/Scala/Enum-in-Scala/

www.hohode.com 4003

Scala之枚举

package com.uplooking.bigdata.p2   /**   * scala中的枚举   */ object EnumerationOps extends  App{   val green = TrafficLightColor.GREEN   val red = TrafficLightColor.RED   println("red.id="

tangshiweibbs的专栏 377

Scala 枚举介绍及深入应用

本文详细地总结了Scala枚举的几种实现方式,对我们更好地进行函数式编程有很好地指导和帮助。 Scala 枚举示例和特性 枚举(Enumerations)是一种语言特性,对于建模有限的实体集来说特别有用。一个经典的例子是将工作日建模为一个枚举:每个七天都有一个值。Scala和许多其他语言一样,提供了一种表示枚举的方法: object Weekday extends Enumeration {...

weixin_30951231的博客 371
上一篇: scala 加载properties文件
下一篇: IDEA 同一个工程下不同模块之间的类相互调用
Code_LT
博客等级 码龄10年 307粉丝 182原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值