惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - cindy_zl

SAP SD销售与分销模块 Agent认知框架ReAct&Plan RAG系统优化 RAG检索优化 RAG架构 SAA-C02-架构师助理级-英文版-Q1 scala-数组 navicat mysql创建存储过程报错 安装完kali出现中文乱码 Spark SQL是处理结构化的数据 SPARK SQL ERROR: Detected cartesian product for INNER join between logical plans报错解决方法 scala集合三大类(seq序列,set集,map映射)——map映射 scala集合三大类(seq序列,set集,map映射)——set集合 scala集合三大类(seq序列,set集,map映射)——list序列 scala元组及拉链操作 scala的map映射 scala数组 scala方法和涵数的声明以及方法转换成涵数 scala的基础数据类型&if条件表达式&for循环
scala的lazy关键字
cindy_zl · 2019-09-18 · via 博客园 - cindy_zl

scala里面的lazy一般是一个关键字,多用于放在一个变量的前面,这样表示这个变量是一个惰性变量

package day02

/**
* 在scala中用Lazy定义的变量叫惰性变量,会实现延迟加载,即在编译的时候并没有执行,
* 惰性变量只能是不可变变量,且只有在调用惰性变量时,才会去实例化这个变量。
*/

object ScalaLazyDemo1 {

def init(): Unit = {
println("call init()...")
}

def main(args: Array[String]): Unit = {
val property = init() //没有用Lazy修饰
println("after init()")
println(property)
}

}

//执行结果
/*
call init()...
after init()
()
*/

object ScalaLazyDemo2 {

def init(): Unit = {
println("call init()...")
}

def main(args: Array[String]): Unit = {
lazy val property = init() //用Lazy修饰
println("after init()")
println(property)
}

}
/*
执行结果
after init()
call init()...
()
*/