当前位置:网站首页>Kotlin apply method
Kotlin apply method
2022-06-11 02:29:00 【ScottePerk】
apply Method can merge multiple steps . Some configurations can be made in advance . Very easy to use .
For example, the following code , Code 1 implements the configuration of a read-only file in the traditional way , Code 2 encapsulates this code into apply Inside , Compared with the first , The advantage is that the code set , The structure is clear .
Here are a few points to explain .
1.apply Will be able to this Pass in lambda expression , That is to say {} Inside , Code one file Variable .
2.apply return file Oneself .
fun main() {
// Code 1
var file = File("test.txt");
file.setExecutable(true)
file.setReadable(true)
file.setWritable(false)
// Code 2
var readOnlyfile = file.apply() {
setExecutable(true)
setReadable(true)
setWritable(false)
}
readOnlyfile.mkdir();
}
边栏推荐
- C language principle explanation and code implementation of scalable / reduced thread pool
- Go develop web
- NFT Insider #61:Animoca Brands 在 340 项投资中持有 15 亿美元的加密资产
- Tencent test development post interview programming questions
- Optimized dispatching (thermal power, wind energy and energy storage) [matlab code implementation]
- Bingbing learning notes: find the greatest common divisor and the least common multiple. Complex version reverse string
- Test questions and answers of 2022r1 quick opening pressure vessel operation certificate
- 渗透测试-安全服务体系+OWASP top 10
- cannot import name ‘dtensor‘ from ‘tensorflow. compat. v2.experimental‘
- Enrichment of core knowledge points of interface automation to add points to the interview
猜你喜欢

Redis learning notes (continuously updating)

NFT Insider #61:Animoca Brands 在 340 项投资中持有 15 亿美元的加密资产

Seven principles that should be known by software testers

Principle of everything for fast search

Oracle collects statistics

Li Kou brushing questions - hash table

Tencent test development post interview programming questions

English subtitle video translated into Chinese subtitles

金属有机框架MOF-Al(DIBA),MOF-Zr(DIBA),MOF-Fe(DIBA)包载姜黄素/羧苄西林/MTX甲氨蝶呤/紫杉醇PTX/阿霉素DOX/顺铂CDDP/CPT喜树碱等药物
![[3.delphi common components] 4 Select class component](/img/36/e78ee0c082bc36be6dbc49d0e12521.jpg)
[3.delphi common components] 4 Select class component
随机推荐
Unity3d model skin changing technology
When a logical deletion encounters a unique index, what are the problems and solutions?
What is the relationship between precious metal silver and spot Silver
2022 safety officer-b certificate examination question bank and answers
Byte beating client R & D Intern Tiktok side
During SSH configuration key login, you need to pay attention to whether the private key is set with a password
Find - (block find)
Modify release opening animation
Cyclodextrin metal organic framework( β- Cd-mof) loaded with dimercaptosuccinic acid / emodin / quercetin / sucralose / diflunisal / omeprazole (OME)
Knowledge competition of safety production month -- how much do you know about new safety law
String operation methods: replace, delete and split strings
Unity HTC and Pico are the same
Find - (half find / half find)
2022 simulated 100 questions and answers for crane driver (limited to bridge crane) examination
Redis learning notes (continuously updating)
CRS-5017
[parallel and distributed systems] cache learning
About stepping on the pit diary and the association of knowledge points
力扣刷题篇——哈希表
Project load failed