Kotlin网站声明:
Kotlin is 100% interoperable with Java.
Kotlin是Java的子集/超集吗?
此外,文档还指出Kotlin与JavaScript兼容,那么如何编译它以支持两者? Kotlin是Xamarin的跨平台语言吗?
Java是否插回到Kotlin?
解决方法:
Kotlin is a statically-typed programming language that runs on the
Java Virtual Machine and also can be compiled to JavaScript source
code.
这意味着Kotlin有两个编译器,前者生成可以在JVM中执行的字节码,后者只生成JavaScript.
这使得Kotlin可以与这两种语言互 *** 作.
关于Kotlin和Java
例如,当Java字节码和Kotlin字节码在同一个JVM中运行时,您可以使用call Java from Kotlin和/或call Kotlin from Java.
07002 and 07003
Kotlin is designed with Java Interoperability in mind. Existing Java
code can be called from Kotlin in a natural way, and Kotlin code can
be used from Java rather smoothly as well.Null-Safety and Platform Types
Any reference in Java may be null, which makes Kotlin’s requirements
of strict null-safety impractical for objects coming from Java. Types
of Java declarations are treated specially in Kotlin and called
platform types. Null-checks are relaxed for such types, so that safety
guarantees for them are the same as in Java
关于Kotlin和JavaScript
同样,当您使用生成JavaScript的Kotlin编译器时,您可以在同一个JavaScript engine中将Kotlin与JavaScript源一起运行.
所以你可以call Kotlin from Javascript和/或call Javascript from Kotlin.
07007
Kotlin was designed for easy interoperation with Java platform. It
sees Java classes as Kotlin classes, and Java sees Kotlin classes as
Java classes. However, JavaScript is a dynamically-typed language,
which means it does not check types in compile-time. You can freely
talk to JavaScript from Kotlin via dynamic
types, but if you want the full power of Kotlin type system, you can
create Kotlin headers for JavaScript librarIEs.07008
Kotlin compiler generates normal JavaScript classes, functions and
propertIEs you can freely use from JavaScript code. Nevertheless,
there are some subtle things you should remember. To prevent spoiling the global > object, Kotlin creates an object that contains all Kotlin declarations
from the current module. So if you name your module asmyModule
, all > declarations are available to JavaScript
viamyModule
object.
关于你关于Xamarin的问题,我只会说Xamarin和Kotlin是两个完全不同的东西.您可以将Xamarin与Ionic或PhoneGap进行比较,因为它们是可以让您创建多平台应用程序的产品.
另一方面,Kotlin是一种语言,您可以编译该语言以在不同的环境和/或设备上运行程序.
总结以上是内存溢出为你收集整理的Kotlin如何与Java和JavaScript互 *** 作?全部内容,希望文章能够帮你解决Kotlin如何与Java和JavaScript互 *** 作?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)