The scala lazy keywords

scala lazy generally inside a keyword used for in front of a variable, so that this variable is represented by a variable inert

day02 Package Penalty for 

/ **
* Lazy using the scala-defined variables called variable inertia, lazy loading will be achieved, and that is not performed at compile time,
* variables can only be inert immutable variable, and only when calling inert variable, only to instantiate this variable.
* /

Object ScalaLazyDemo1 {

DEF the init (): Unit = {
the println ( "Call the init () ...")
}

DEF main (args: the Array [String]): Unit = {
Val Property = the init () // no use Lazy modifying
the println ( "After the init ()")
(Property) the println
}

}

// execution result
/ *
Call the init () ...
After the init ()
()
* /

Object ScalaLazyDemo2 {

DEF the init (): Unit = {
the println ( "Call the init () ...")
}

DEF main (args: the Array [String]): Unit = {
the lazy = Val Property the init () // modified with Lazy
the println ( "After the init ()")
the println (Property)
}

}
/ *
execution result
After the init ()
Call the init () ...
()
* /

Guess you like

Origin www.cnblogs.com/cindy-zl24/p/11541251.html