val logEnable = false
def log(msg: => String) =
    if (logEnable) println(msg)
val MSG = "programing is running"
log(MSG + 1 / 0)

 

class Stu(private val name:String,private var age:Int)
{
	def Name = name;
	def Age = age;
	def Age_=(age: Int) = this.age = age;
}
val s = new Stu("wengmj",36);
s.Age=37
println(s.Age);

 

import scala.language.reflectiveCalls

def withClose[A <: { def close(): Unit }, B](closeAble: A)
  (f: A => B): B =
  try {
    f(closeAble)
  } finally {
    closeAble.close()
  }
class Connection {
  def close() = print("close Connection")
}
val conn: Connection = new Connection()
val msg = withClose(conn) { conn =>
  {
    println("do something with Connection")
    "123456"
  }
}

  

import scala.language.implicitConversions
import scala.language.reflectiveCalls

object M
{
  implicit def ask(x:Boolean)=new{def ?(a:Any,b:Any):Any=if(x) a else b}
  def main(args:Array[String])
  {	
    print((3>2) ? ("hello","world"));
  }
}
posted on 2016-02-01 14:53  scala  阅读(449)  评论(0编辑  收藏  举报