我决定写一个 Vert.x 在一个简单的示例中结合彩票3d字谜应用程序,因为我真的很感兴趣 反应式编程 和喜欢使用 科特林。在这篇文章中,我将提供有关Vert.x的一些基本信息,作为在JVM上编写响应式应用程序的工具集,还介绍了彩票3d字谜。最后,我想演示如何在Gradle中设置此应用程序。
Vert.x-反应性编程工具包
Vert.x是用于在Java虚拟机上编写反应式应用程序的“工具包”,而不是框架。如定义 “反应式宣言” (2014年9月16日发布)“反应式编程”是一种架构软件模式,旨在解决当今对现代软件应用程序的需求。更准确地说,预计反应式应用程序将``更加灵活,松耦合和可扩展'',``易于开发''以及最终``高度集成''。 负责任的”,这听起来确实不错,不是吗?
作为一个重要的含义,这些应用程序需要 消息驱动,这意味着应用程序仅通过 异步, 非阻塞 消息。 Vert.x特别适用于宣言,并提供了一个很棒的工具集,可以非常轻松地开发反应式软件。
它也是模块化的,非常快速且轻巧的(〜650kB),并且为其他(也许是众所周知的)微服务框架提供了合理的替代方案。
科特林
科特林 是一种非常新的开源JVM语言,由的伟大人物赞助 JetBrains,目前在版本1.1.50中可用。它的类型是静态的,并且彩票3d字谜与Java完全可互操作。 JetBrains创建这种语言的想法是找到一种更具生产力的Java替代品,同时仍与Java兼容。我认为每个与之合作的Java开发人员Groovy或Scala知道Java需要一些简单的代码来完成一些简单的任务,并且存在很多缺陷。 科特林受到Java,Scala和更多现代语言的启发,试图结合所有这些优势。
就在几天前,Google宣布彩票3d字谜将成为今年的官方Android编程语言。 Google I / O会议。我认为这是迄今为止彩票3d字谜所取得的最大成就,我要祝贺JetBrains取得这一里程碑!
现在该展示一下彩票3d字谜的一些语言功能:
局部变量类型推断
以下代码行演示了如何在彩票3d字谜中定义变量:
var myvar1 = 100
var myvar2 = "text"
The types of myvar1
and myvar2
(Int
and String
), are being inferred behind the scenes for us. This works in most cases but, of course, it's also possible to declare the variable type explicitly as in var myvar3: Double = 1.0
.
资料类别
Just think of a Java class Person
, having attributes like name
, age
, job
. The class is supposed to override Object
's toString()
, hashCode()
& equals()
methods and of course provide getters and setters for each attribute.
data class Person(val name: String, val age: Int, val job: String)
这就是您需要用彩票3d字谜(实时保护程序)编写的全部内容。
空安全
We all know what NullpointerException
s are - we all hate them. 彩票3d字谜 tries to eliminate these 通过 distinguishing between nullable and not-null references. Guess, what's the default? Absolutely, the non-null reference type, i.e. a variable of type String
cannot point to null
.
Just for the records, the corresponding nullable type would be String?
.
仅此一项并不会带来太大的区别,因此使用可为空的类型需要我们处理所有容易发生NPE的情况,如下所示:
val iCanBeNull: String? = null;
//do some hard work with the string
iCanBeNull?.length
Line 3 will result in the String’s length if iCanBeNull
is not null
, and to null
otherwise. Trying to naively call iCanBeNull.length
will not compile.
字符串模板
任何人都容易理解的另一个非常有用的功能:
var insertMe = "Reader"
//Prints >>Hello Reader<< on Console
println("Hello $insertMe")
更多
上面显示的示例只是我非常喜欢彩票3d字谜和 也希望在Java中找到。我已经与彩票3d字谜一起工作了几个月,并成为忠实粉丝。我认为一开始,可能需要一些时间来适应Java不同的语法,但是很快您会遇到很多事情,您实际上会爱上并且不想再错过了...
顺便说说:上述某些语言功能也可以在“ JDK增强建议”(JPE)的长长列表中找到,例如 JEP 286:局部变量类型推断,由Brian Goetz撰写。
Let’s finally do something! - The setup for彩票3d字谜反应式编程
在下面,您可以看到我的Gradle文件,其中包含以下任务:
- 科特林针对Java 1.8进行编译(此处不需要1.6支持)。
- 为Vert.x,彩票3d字谜,日志记录添加了依赖项& Testing
- We use the
application
plugin for building an executable JAR (Main-Class is added to Manifest)
The 科特林 file "Starter.kt" contains the application's entry point: themain
method. The compiler generates a "StarterKt" class, which has to be the Main-Class.
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.tasks.*
val kotlin_version = "1.1.50"
val vertx_version = "3.4.2"
plugins {
application
eclipse
kotlin("jvm")
}
tasks.withType {
kotlinOptions.jvmTarget = "1.8"
}
application {
mainClassName = "de.swirtz.vertx.standalone.webserver.StarterKt"
applicationName = "kotlinwithvertx"
version = "1.0-SNAPSHOT"
group = "example"
}
dependencies {
compile(kotlin("stdlib", kotlin_version))
compile(kotlin("reflect", kotlin_version))
with("io.vertx:vertx") {
compile("$this-core:$vertx_version")
compile("$this-web:$vertx_version")
compile("$this-web-templ-thymeleaf:$vertx_version")
}
compile("org.slf4j:slf4j-api:1.7.14")
compile("ch.qos.logback:logback-classic:1.1.3")
testCompile(kotlin("test-junit", kotlin_version))
testCompile("junit:junit:4.11")
testCompile("io.vertx:vertx-unit:$vertx_version")
}
repositories {
mavenCentral()
jcenter()
}
val fatJar = task("fatJar", type = Jar::class) {
baseName = application.applicationName
manifest {
attributes["Main-Class"] = application.mainClassName
}
from(configurations.runtime.map {
if (it.isDirectory) it else zipTree(it)
})
with(tasks["jar"] as CopySpec)
}
tasks {
"build" {
dependsOn(fatJar)
}
}
Afterward, you can build
and run
your application as shown here:
- ./gradlew构建
- ./gradlew运行
您可以在上查看我的示例代码 的GitHub,其中包括使用HTTP进行路由的一些示例 Vert.x网站,还展示了如何使用模板引擎。享受彩票3d字谜反应式编程的乐趣。
Simon是总部位于德国的软件工程师,具有7年为JVM和JavaScript编写代码的经验。他’他对尽可能多地学习新事物充满热情,并且是科特林(彩票3d字谜)的自发狂热者。
[…]我在Vert.x上的帖子中介绍了彩票3d字谜的更多功能。 […]
[…]有关彩票3d字谜功能的详细介绍,您可以看一下我最近发布的类似文章。 […]
[…上一次,由于反应式编程获得了影响,无阻塞编程变得越来越流行。 2.其实是“possibly suspending”因为这样的功能可能[…]
[…]是基于Vert.x工具包的彩票3d字谜 Web应用程序。在我撰写的这篇文章中[了解更多有关该技术的信息]…]
[…]来自示例vert.x应用程序,并定义一个本地函数,此函数以后将重用两次。简化[…]
[…]例如RxJava,Vert.X或Akka。如果您从未遇到过这些内容,可以先阅读Vert.X在彩票3d字谜上的信息[…]
[…] Scala功能JetBrains被认为相关且适合彩票3d字谜吗?我喜欢阅读这篇文章,如果你’对更多彩票3d字谜感兴趣[…]