当前位置:网站首页>Class, interface, function

Class, interface, function

2022-06-21 17:40:00 Lighthouse @kuaidao

Preface

Various technical terms are increasing , To learn programming well, you must first understand technical terms , Then we can make a general judgment on the technology industry as a whole . It is often used for a certain knowledge point in learning, but it is easy to be confused when reading official documents , The corresponding relationship between professional terms and their own knowledge .blog Lie in listing java and kotlin , class 、 Interface 、 function species .

 Insert picture description here
 Insert picture description here

function

Lambda It's an object .

Lambda An expression is a function interface object
lambda expression :block:String.()->Unit

kotlin inline keyword

Every time a higher-order function is called , Will create an anonymous inner class . The function is set to Inline after . The expression of the function will be embedded in the called place at compile time , Achieve the effect of performance optimization . Reduce class loading opportunities .

inline keyword Function compared with ordinary function bytecode and found

  1. Use inline after The number of bytecode lines is reduced relative to non inline The bytecode class of the function
  2. Use inline There will be no... In bytecode kotlin/jvm/lambda Class inheritance , Ordinary functions have inheritance kotlin/jvm/lambda .

Intelj IDE Check bytecode (java and kotlin The way )

 Insert picture description here
kotlin Check bytecode
 Insert picture description here

Kotlin Function type : Function types have a pair of parentheses , And it has a return value

expression (Int)->Unit

Functional expression (SAM) Interface

An interface with only one abstract method is called a functional interface or SAM( A single abstract method ) Interface . A functional interface can have multiple non abstract members , But there can only be one abstract member .

Statement :

fun interface KRunnable {
    
   fun invoke()
}

Functional interface conversion : Lambda conversion SAM

problem :

1. What is bytecode
2. Basic knowledge of bytecode
3. Higher order functions and Lambda expression

Java Lambda and Kotlin Lambda The difference between

原网站

版权声明
本文为[Lighthouse @kuaidao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211518336927.html