clwn.net
当前位置:首页 >> sCAlA.mAtChError >>

sCAlA.mAtChError

一、简单例子: 1 abstract class Expr 2 case class Var(name:String) extends Expr 3 case class Number(num:Double) extends Expr 4 case class UnOp(operator : String , arg : Expr) extends Expr 5 case class BinOp(operator : String , ...

先抛个问题,下面的语句是否都合理(编译通过),哪些会引起模式匹配? scala> val a = 100 scala> val A = 100 scala> val a@b = 100scala> val (a,b) = (100,200)scala> val (a,B) = (100,200) //第二个变量大写scala> val Array(a,b) = Array(1...

object MatchTest extends App { val weekString = Vector("星期一","星期二","星期三","星期四","星期五","星期六","星期日") import scala.io.StdIn while(true){ val line = StdIn.readLine("please input a number to get week day name, -1...

Object不能直接转化成Integer 你首先需要把它转化成String list.get(i).toString(); 再使用 Integer.valueOf(list.get(i).toString()); 有很多转化都...

参考答案阳光好温柔。好久好久没有在森林里游荡了。

要写一个匹配各类计数法的正则表达式比较麻烦,我这里只是一个最简单的整数匹配正则式 def isIntByRegex(s : String) = { val pattern = """^(\d+)$""".r s match { case pattern(_*) => true case _ => false }}isIntByRegex("123")isIntByRege...

在Scala中存在case class,它其实就是一个普通的class。但是它又和普通的class略有区别,如下: 1、初始化的时候可以不用new,当然你也可以加上,普通类一定需要加new; scala> case class Iteblog(name:String) defined class Iteblog scala> v...

val l = List(1,2,3) val s = l match { case list @ List(1, _*) => s"a start value is 1 list :$list" case list : List[_] => s"a start value not 1 list" } 看书上说是为了取出模式匹配后对应的原来输入值,例如上面例子中的模式匹配是为...

def unapplySeq(target: Any): Option[List[String]] = target match { case s: CharSequence => val m = pattern matcher s if (runMatcher(m)) Some((1 to m.groupCount).toList map m.group) else None case m: Match => unapplySeq(m.matche...

val s1="100"val r1=scala.util.Try(s1.toInt)val result = r1 match { case Success(_) => "Int" ; case _ => "NotInt" }

网站首页 | 网站地图
All rights reserved Powered by www.clwn.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com