DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

scala的方法和变量


以下都是合法的方法声明

def myMethod

def myMethod = "Moof"

def myMethod() = "Moof"

def myMethod(): String = "Moof"

def foo(a: Int): String = a.toString

def f2(a: Int, b: Boolean): String = if (b) a.toString else "false"

def listT: List[T] = p :: Nil //类型参数

def sumT <: Number: Double = as.foldLeft(0d)( + .doubleValue) //有限定范围的类型参数

def largest(as: Int*): Int = as.reduceLeft((a, b) => a max b) //可变长度参数列表

def mkStringT: String = as.foldLeft("")( + .toString)



Published

Nov 3, 2011

Last Updated

Nov 3, 2011

Category

Tech

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor