kotlin面试
Kotlin is the latest JVM programming language from the JetBrains. Google has made it the official language for Android Development along with Java. Developers say it addresses the issues faced in Java programming. I have written a lot of Kotlin tutorials and here I am providing important kotlin interview questions.
Kotlin是JetBrains中最新的JVM编程语言。 Google使其与Java一起成为Android开发的官方语言。 开发人员说,它解决了Java编程面临的问题。 我写了很多Kotlin教程,在这里我提供了重要的Kotlin面试问题。
Kotlin面试问题 (Kotlin Interview Questions)
Here I am providing Kotlin Interview Questions and Answers that will help you in your Kotlin Interviews. These Kotlin interview questions are good for beginners as well as experienced programmers. There are coding questions too to brush up your coding skills.
在这里,我提供了Kotlin面试问答,可以帮助您进行Kotlin面试。 这些Kotlin面试问题对初学者和经验丰富的程序员都非常有用。 还有一些编码问题可以提高您的编码技能。
Kotlin的目标平台是什么? Kotlin-Java如何互操作? (What’s the Target Platform of Kotlin? How is Kotlin-Java interoperability possible?)
Java Virtual Machine(JVM) is the Target Platform of Kotlin. Kotlin is 100% interoperable with Java since both, on compilation produce bytecode. Hence Kotlin code can be called from Java and vice-versa.
Java虚拟机(JVM)是Kotlin的目标平台。 Kotlin可与Java 100%互操作,因为两者在编译时都会产生字节码。 因此,可以从Java调用Kotlin代码,反之亦然。
您如何在Kotlin中声明变量? 声明与Java声明有何不同? (How do you declare variables in Kotlin? How does the declaration differ from the Java counterpart?)
There are two major differences between Java and Kotlin variable declaration:
- The type of declaration
In Java the declaration look like this:String s = "Java String"; int x = 10;
In Kotlin the declaration looks like:
In Kotlin, the declaration begins with a
val
and avar
followed by the optional type. Kotlin can automatically detect the type using type inference. - Default value
The following is possible in Java:String s:
The following variable declaration in Kotlin is not valid.
Java和Kotlin变量声明之间有两个主要区别:
- 申报类型
在Java中,声明如下所示:String s = "Java String"; int x = 10;
在Kotlin中,声明如下所示:
在Kotlin中,声明以
val
和var
开头,后跟可选类型。 Kotlin可以使用类型推断自动检测类型。 - 默认值
Java中可能有以下内容:String s:
Kotlin中的以下变量声明无效。
- The type of declaration
val和var声明有什么区别? 如何将字符串转换为Int? (What’s the difference between val and var declaration? How to convert a String to an Int?)
val
variables cannot be changed. They’re like final modifiers in Java. Avar
can be reassigned. The reassigned value must be of the same data type.fun main(args: Array<String>) { val s: String = "Hi" var x = 5 x = "6".toInt() }
We use the
toInt()
method to convert the String to an Int.val
变量不能更改。 它们就像Java中的最终修饰符。 可以重新分配var
。 重新分配的值必须具有相同的数据类型。我们使用
toInt()
方法将String转换为Int。什么是Kotlin中的Null安全性和Nullable类型? 猫王算子是什么? (What’s Null Safety and Nullable Types in Kotlin? What is the Elvis Operator?)
Kotlin puts a lot of weight behi