Kotlin basics 2. Function application: fun

What are the differences between Kotlin's use of functions and java? Let’s start with the most common onCreate method and see what are the differences between the two. The following is the onCreate function code written in Java:
insert image description here
and the onCreate function code written in Kotlin is as follows: Comparing the
insert image description here
two, you can see that the two main The following differences are:

(1) Java uses "@Override" to indicate that the function overloads the method of the parent class, while Kotlin uses lowercase "override" to express the overload operation on the same line.

(2) Java uses "public" to indicate that the function is a public method, and Kotlin's default function is public, so the keyword "public" is omitted.

(3) Java uses "void" to indicate that the function has no return parameters, while the keyword "void" does not exist in Kotlin. If there are no return parameters, no special explanation is required.

(4)Kotlin has added the keyword "fun", which means that this is a function definition. Its format is similar to the keyword "class" in Java, but the keyword "fun" does not exist in Java.

Guess you like

Origin blog.csdn.net/qq_35091074/article/details/123275539