Java Runtime Version 1.6 0 10 Download Mac
Try Kotlin
fun main() { val name = "stranger" // Declare your first variable println("Hi, $name!") // ...and use information technology! print("Electric current count:") for (i in 0..ten) { // Loop over a range from 0 to 10 print(" $i") } } Why Kotlin
Modern, curtailed and safe programming language
Easy to option up, then you lot can create powerful applications immediately.
-
Concise
data course Employee( val name: String, val electronic mail: String, val company: String ) // + automatically generated equals(), hashCode(), toString(), and copy() object MyCompany { // A singleton const val proper noun: String = "MyCompany" } fun main() { // Function at the top level val employee = Employee("Alice", // No `new` keyword "alice@mycompany.com", MyCompany.proper name) println(employee) } -
Safe
fun respond(condition: Boolean): String? = // Nullability is part of Kotlin'southward type arrangement if (condition) "I'm fine" else null fun error(): Nothing = // Always throw an exception throw IllegalStateException("Shouldn't be here") fun main() { val condition = true // Try replacing `true` with `false` and run the sample! val message = respond(condition) // The result is nullable // println(message.uppercase()) // This line doesn't compile println(message?.supersede("fine", "okay")) // Access a nullable value in a safe mode if (message != null) { // If you check that the type is right, println(message.capital letter()) // the compiler will smart-cast information technology for you } val nonNull: String = // If the null-instance throws an error, respond(condition = truthful) ?: mistake() // Kotlin can infer that the result is non-null println(nonNull) } -
Expressive
fun main() { //sampleStart val map = mapOf(ane to "1", 2 to "2") for ((one thousand, v) in map) { // Traverse a map or a list of pairs println("$yard -> $five") } fun obtainKnowledge() = Pair("The Respond", 42) // Single-expression functions val (description, answer) = obtainKnowledge() // Destructure into a pair of ii variables println("$description: $respond") getText()?.permit { // Apply an action to a nullable expression sendEmailTo("alice@example.com", it) // if information technology's not null } createEmptyWindow() .apply { // Configure properties of an object width = 300 height = 200 isVisible = true }.too { w -> // Perform an additional functioning on a call chain showWindow(w) } val fixedIssue = issueById["13456"] ?.takeIf { information technology.condition == Condition.FIXED } // Use the value only if the condition is true println(fixedIssue) //sampleEnd } data class Window(var width: Int, var peak: Int, var isVisible: Boolean) fun createEmptyWindow() = Window(0, 0, false) fun showWindow(window: Window) { println("Showing $window") } fun getText(): String? = "How-do-you-do! You lot've won the lottery! Pay the attached bill to get the prize." fun sendEmailTo(to: String, message: String) { println("Sending e-mail to $to: \north$message") } enum class Status { OPEN, Fixed, IN_PROGRESS } information form Event(val status: Status) val issueById = mutableMapOf( "13456" to Event(Status.Fixed) ) -
Interoperable
// Use any existing JVM library or framework // Call Kotlin code from Java without an issue @SpringBootApplication class DemoApplication fun main(args: Array<String>) { runApplication<DemoApplication>(*args) } @RestController class MessageResource { @GetMapping fun index(): List<Message> = listOf( Message("1", "Hello!"), Message("two", "Bonjour!"), Message("iii", "Privet!"), ) } data class Bulletin(val id: Cord?, val text: String)// Write Kotlin lawmaking, compile information technology to JavaScript, and run it in the browser // Use existing JavaScript APIs and libraries import kotlinx.browser.window fun primary() { val body = window.document.body body?.innerHTML += "<b>Hello, <i>Kotlin</i></b>" window.setInterval({ body?.innerHTML += "!" }, 1000) }// Use Kotlin wrappers to build applications with JavaScript frameworks such as React import react.* import react.dom.* import kotlinx.html.js.onClickFunction val counter = functionalComponent<Props> { val (count, setCount) = useState(0) push button { attrs.onClickFunction = { setCount(count + 1) } +count.toString() } } -
Multiplatform
// Common // Declare signatures to apply them in the common code // Provide platform-specific implementations in the platform modules expect fun randomUUID(): String wait grade PlatformSocket( url: String ) { fun openSocket(listener: PlatformSocketListener) fun closeSocket(code: Int, reason: String) fun sendMessage(msg: String) } interface PlatformSocketListener { fun onOpen() fun onFailure(t: Throwable) fun onMessage(msg: String) fun onClosing(code: Int, reason: String) }import java.util.* actual fun randomUUID() = UUID.randomUUID().toString() actual grade PlatformSocket actual constructor(url: String) { // Use okhttp3 in implementation }// iOS import platform.Foundation.NSUUID actual fun randomUUID(): Cord = NSUUID().UUIDString() bodily course PlatformSocket actual constructor(url: String) { // Use platform.Foundation in implementation }// JS // Utilise the `uuid` parcel from npm as dependency actual fun randomUUID(): String = uuidv4() bodily grade PlatformSocket actual constructor(url: String) { // Implementation on meridian of WebSockets }
A productive manner to write server‑side applications
Compatible with the Java ecosystem. Utilize your favorite JVM frameworks and libraries.
Cross-platform layer for native applications
Share awarding logic between web, mobile, and desktop platforms while keeping an experience native to users.
Relieve time and get the do good of unlimited access to features specific to these platforms.
Big, friendly and helpful
community
Kotlin has peachy back up and many contributors in its fast-growing global community. Bask the benefits of a rich ecosystem with a broad range of community libraries. Aid is never far away — consult extensive community resources or inquire the Kotlin squad directly.
Java Runtime Version 1.6 0 10 Download Mac
Posted by: mckeeforaceir.blogspot.com

0 Komentar
Post a Comment