java使用枚举类型,所以不用
scala但是没有枚举类型,如果项目中 需要 用到枚举或者类似枚举 。scala 就需要 使用其他方式来实现。
基本来说 有三种
第一种 ,就是在项目中单独写一个java文件,在文件中声明 枚举类型,然后在其他scala文件中去引入 这个java文件类 ,就可以达到 使用枚举类型的方法
第二种 ,就是使用 case 类来达到当做枚举类型的使用,可以参考
https://github.com/ktonga/tweet-virality/blob/12fe9e789234b95a1a337ee887d90e5a021fca92/app/com/github/ktonga/tweetvirality/models/twitter/Neo4j.scala
case class NeoLabel(name: String) extends Label
case class NeoRelType(name: String) extends RelationshipType
val User = NeoLabel("User")
val Tweet = NeoLabel("Tweet")
val Follows = NeoRelType("Follows")
val FollowedBy = NeoRelType("FollowedBy")
val Twitted = NeoRelType("Twitted")
val TwittedBy = NeoRelType("TwittedBy")
在调用的时候
NeoLabel.User
NeoLabel.Tweet
第三种使用 封闭的trait 来实现
class enum extends scala.annotation.StaticAnnotation;
@enum sealed trait AggregateOp extends scala.Product with scala.Serializable {
def json: String
};
object AggregateOpEnums {
case object Values extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"values\""
};
case object Count extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"count\""
};
case object Valid extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"valid\""
};
case object Missing extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"missing\""
};
case object Distinct extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"distinct\""
};
case object Sum extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"sum\""
};
case object Mean extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"mean\""
};
case object Average extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"average\""
};
case object Variance extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"variance\""
};
case object Variancep extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"variancep\""
};
case object Stdev extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"stdev\""
};
case object Stdevp extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"stdevp\""
};
case object Median extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"median\""
};
case object Q1 extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"q1\""
};
case object Q3 extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"q3\""
};
case object Modeskew extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"modeskew\""
};
case object Min extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"min\""
};
case object Max extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"max\""
};
case object Argmin extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"argmin\""
};
case object Argmax extends AggregateOp with scala.Product with scala.Serializable {
val json: String = "\"argmax\""
}
};