当前位置:网站首页>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();
}
边栏推荐
- 深度学习基础篇【4】从0开始搭建EasyOCR并进行简单文字识别
- Talk about an annotation implementation interface retry
- Unity camera camera about layer mask cullingmask settings
- MOFs, metal organic framework materials of folic acid ligands, are loaded with small molecule drugs such as 5-fluorouracil, sidabelamine, taxol, doxorubicin, daunorubicin, ibuprofen, camptothecin, cur
- In the past 10 years, from zero foundation testing to test architect, he has made himself successful
- How to guarantee the data quality of data warehouse?
- Metal organic framework MOF Al (Diba), MOF Zr (Diba), MOF Fe (Diba) loaded with curcumin / carboxybenzylpenicillin /mtx methotrexate / paclitaxel ptx/ DOX / cisplatin cddp/cpt camptothecin and other d
- 可扩/减容线程池C语言原理讲解及代码实现
- 常见漏洞的防御措施整理
- 2022 simulated 100 questions and answers for crane driver (limited to bridge crane) examination
猜你喜欢

贵金属白银和现货白银之间是什么关系

To view the data in redis, in addition to the command line and client, you have a third option

MOFs, metal organic framework materials of folic acid ligands, are loaded with small molecule drugs such as 5-fluorouracil, sidabelamine, taxol, doxorubicin, daunorubicin, ibuprofen, camptothecin, cur

Enrichment of core knowledge points of interface automation to add points to the interview

叶酸配体的金属有机骨架材料MOFs负载5-氟尿嘧啶,西达本胺,紫杉醇,阿霉素,柔红霉素,布洛芬,喜树碱,姜黄素,藤黄酸等小分子药物

Multilevel mesoporous organometallic framework material zif-8 loaded with lactic acid oxidase (LOD) / ferric oxide (Fe304) / doxorubicin / insulin /cas9 protein / metronidazole / emodin methyl ether

2022 high altitude installation, maintenance and removal of simulated examination platform of theoretical question bank

深度学习基础篇【4】从0开始搭建EasyOCR并进行简单文字识别

InfoQ geek media's 15th anniversary solicitation | in depth analysis of container runtime Technology

Jetpack Compose Scaffold和BottomAppBar(底部导航)
随机推荐
421. maximum XOR value of two numbers in the array
Merge sort ()
Unity3d detects that the object is not within the range of the camera
Knowledge competition of safety production month -- how much do you know about new safety law
力扣刷题篇——哈希表
企业展厅设计能为企业带来什么?
Implementing queues with stacks
SQL | return customer name, relevant order number and total price of each order
动态给对象添加属性
Jetpack Compose Box控件
Setting access to win10 shared folder without verification
年金保险理财产品可以复利吗?利率是多少?
Optimized dispatching (thermal power, wind energy and energy storage) [matlab code implementation]
Ortele has obtained three rounds of financing nine months after its establishment, and hard discount stores have found new ways to grow?
Find - (sequential search)
The annual salary of testers in large factories ranges from 300000 to 8K a month. Roast complained that the salary was too low, but he was ridiculed by netizens?
Jetpack Compose Scaffold和TopAppBar(顶部导航)
Blue Bridge Cup: the sixth preliminary round - "temperature recorder"
889. construct binary tree according to preorder and postorder traversal
Unity HTC and Pico are the same