PHP       WEB       3GL   4GL   5GL      

Kotlin

Kotlin - , JVM JetBrains. JavaScript. , .

, Java:

package my.demo

import java.util.*

// ...

Java, , : .

. .

Int Int:

fun sum(a: Int, b: Int): Int {
  return a + b
}

:

fun sum(a: Int, b: Int) = a + b

, (void Java):

fun printSum(a: Int, b: Int): Unit {
  print(a + b)
}

Unit :

fun printSum(a: Int, b: Int) {
  print(a + b)
}

. .

( ) :

val a: Int = 1
val b = 1   //  `Int`  
val c: Int  //  ,    
c = 1       //  

:

var x = 5 //  `Int`  
x += 1

. .

, Java JavaScript, Kotlin .

//  

/*  
     . */

Java, .

. Documenting Kotlin Code .

$name ${name}:

fun main(args: Array<String>) {
  if (args.size == 0) return

  print("First argument: ${args[0]}")
}

. .

fun max(a: Int, b: Int): Int {
  if (a > b)
    return a
  else
    return b
}

if (. . if ... else ):

fun max(a: Int, b: Int) = if (a > b) a else b

. if.

Nullable- null

nullable ( ?) null.

null str :

fun parseInt(str: String): Int? {
  // ...
}

, null:

fun main(args: Array<String>) {
  if (args.size < 2) {
    print("   ")
    return
  }

  val x = parseInt(args[0])
  val y = parseInt(args[1])

  //  `x * y`   ,     null
  if (x != null && y != null) {
    // x  y    -nullable    null
    print(x * y)
  }
}

  // ...
  if (x == null) {
    print("    '${args[0]}'")
    return
  }
  if (y == null) {
    print("    '${args[1]}'")
    return
  }

  // x  y    -nullable    null
  print(x * y)

. Null-.

is , . , :

fun getStringLength(obj: Any): Int? {
  if (obj is String) {
    //    `obj`    `String`
    return obj.length
  }

  // `obj`   `Any`    
  return null
}

fun getStringLength(obj: Any): Int? {
  if (obj !is String)
    return null

  //    `obj`    `String`
  return obj.length
}

fun getStringLength(obj: Any): Int? {
  // `obj`    `String`    `&&`
  if (obj is String && obj.length > 0)
    return obj.length

  return null
}

. .

for

fun main(args: Array<String>) {
  for (arg in args)
    print(arg)
}

for (i in args.indices)
  print(args[i])

. for.

while

fun main(args: Array<String>) {
  var i = 0
  while (i < args.size)
    print(args[i++])
}

. while.

when

fun cases(obj: Any) {
  when (obj) {
    1          -> print("One")
    "Hello"    -> print("Greeting")
    is Long    -> print("Long")
    !is String -> print("Not a string")
    else       -> print("Unknown")
  }
}

. when.

in:

if (x in 1..y-1)
  print("OK")

:

if (x !in 0..array.lastIndex)
  print("Out")

:

for (x in 1..5)
  print(x)

. .

:

for (name in names)
  println(name)

in:

if (text in names) // names.contains(text) is called
  print("Yes")

- :

names
    .filter { it.startsWith("A") }
    .sortedBy { it }
    .map { it.toUpperCase() }
    .forEach { print(it) }

. .

  PHP       WEB       3GL   4GL   5GL         w  

, - . , , .




 18.01.2021 - 11:33: - Personalias -> WHO IS WHO - - _.
18.01.2021 - 09:05: , - War, Politics and Science -> . - _.
18.01.2021 - 08:21: , , - Upbringing, Inlightening, Education -> - _.
18.01.2021 - 07:41: , , - Upbringing, Inlightening, Education -> - _.
17.01.2021 - 17:59: , - War, Politics and Science -> - _.
17.01.2021 - 16:46: , , - Upbringing, Inlightening, Education -> - _.
17.01.2021 - 16:00: - Ecology -> - _.
16.01.2021 - 08:30: - Conscience -> . ? - _.
15.01.2021 - 09:03: , - War, Politics and Science -> - _.
15.01.2021 - 09:03: , , - Upbringing, Inlightening, Education -> - _.
15.01.2021 - 08:20: - Theorizing and Mathematical Design -> - - _.
15.01.2021 - 08:19: , , - Upbringing, Inlightening, Education -> - _.
Bourabai Research -  XXI Bourabai Research Institution