In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What does Kotlin mean? in view of this question, this article introduces in detail the corresponding analysis and answers, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
What is Kotlin
Kotlin is a static programming language for modern multi-platform applications, developed by JetBrains. Kotlin can be compiled into Java bytecode or into JavaScript, making it easy to run on devices without JVM. Kotlin has officially become the official supported development language of Android.
Second, the application field of Kotlin
After learning kotlin, you can become a full stack engineer.
Can not only write web front-end, web back-end, Android mobile, but also write server scripts, desktop games.
III. Characteristics of Kotlin
Static strongly typed language
Run on JVM
Can be compiled into JavaScript code
Compatible with Java100%
IV. The development trend of Kotlin
Open source was launched in 2011, and the number of star on github reached 17k in 2017. At present, Kotlin is used in the full-line editors of petal, Douban APP and JetBrains, and so are many start-ups in China.
Using Kotlin (especially for Android development)
5. Advantages of Kotlin
Full support for Lambda expressions
Data class (Data classes)
Function numerical face quantity and inline function (Function literals & inline functions)
Function extension (Extension functions)
Empty Security (Null safety)
Intelligent conversion (Smart casts)
String template (String templates)
Main constructor (Primary constructors)
Class delegate (Class delegation)
Type inference (Type inference)
Single case (Singletons)
Declare a point variable (Declaration-site variance)
Interval expression (Range expressions)
VI. Functions in Kotlin
Inline function
In Android development, we usually use the Log class to print information. We have to pass two parameters for each method in Log. We can encapsulate the first tag parameter in Kotlin like below, so we only need to pass one parameter.
Inline fun T.debug (log:Any)
{
Log.d (T::class.simpleName, log.toString ())
}
It can get the specific type of T through the generic parameter T, and get its class name-- of course, you can even call its constructor to construct an object if you like-- why can Kotlin do that? Because this code is inline, and the final compilation time is to compile into the code block that calls it, the type of T is actually determined, so Kotlin uses the keyword reified to tell the compiler that the parameter T is not just a device, I want to use it as an actual type.
Adding inline annotations before higher-order functions specifies the inlining of the function, and the inline tag affects the passed lambda function itself: all of these will be associated to the call point. Inlining may cause the generated code to grow, but we can solve it reasonably (don't inline functions that are too large). You can also use noinline to specify that some functions are not inline.
Inline fun foo (inlined: ()-> Uint, @ noinline notInlined: ()-> Unit) {
/ /...
}
Lambda expressions that can be inlined can only be called within inline functions or passed as inline arguments, but noinline's can operate in any way we like: store it in a field, pass it, and so on.
Single expression function
If the function body of a function has only one expression, the function body can be written directly after "=", that is:
Fun double (x: Int): Int = x * 2
Fun eval (expr: Expr): Double = when (expr) {
Is Expr.Const-> expr.number
Is Expr.Sum-> eval (expr.e1) + eval (expr.e2)
Expr.NotANumber-> Double.NaN
/ / the `else` clause is not required because we've covered all the cases
}
The when keyword is used here, which is similar to but more powerful than switch in java.
Anonymous function
/ * *
* Anonymous function, no name, other syntax is similar to regular function
*
* declare an anonymous function, where the body of the function is represented by an expression, that is, a single expression function
, /
Var test3= fun (XRV IntJY Int): Int=x+y
/ * *
* declare an anonymous function, where the function body is represented by a code block
, /
Var test4= fun (XRV IntJi YRU Int): Int {
Return Xeroy
}
/ * *
* declare an anonymous function that can be inferred and omitted when the return type
, /
Var test5= fun (XRO _ IntjntJY _ lnt) = xchangy
Fun main (args: Array) {
Println (test3 (1pm 2))
Println (test4 (1pm 2))
Println (test5 (1pm 2))
}
Higher order functions and lambda expressions
A higher-order function is a function that can accept a function as an argument or return a function. For example, lock () is a good example.
Fun lock (lock: Lock, body: ()-> T): t {
Lock.lock ()
Try {
Return body ()
}
Finally {
Lock.unlock ()
}
}
This is the end of the answer to the question about what Kotlin means. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.