Antaes, Kotlin overview
Kotlin is an object-oriented and functional programming language created by JetBrains. It is the (other) official language for Android development.
- Interoperability with JVM
- Cross-platform
- Statically typed with type inference
- Object-oriented
- Functional
- Target JVM or JS
- One of the fastest growing language
- Open-source
- Fully supported by IntelliJ with code conversion from/to Java
- Already a lot of dedicated tools, frameworks
fun main() = println("Hello")
- Null safe by default
- Extension function
- Complex switch cases
if
...else
andtry
...catch
(and a lot more) are instructions with a return value, making the java ternary operator obsolete.- Ranges (
1..10
for instance) - Data classes
- Object (singleton)
- Companion object
- Delegated properties
- Default value for method parameters
- Named arguments
let
keyword allowing object initialization and configuration in a single block- Destructuring declaration
- Language documentation
- Nice overview of the language with some editable code samples
- Online editor for a simple Kotlin file
- Training with a set of exercises to complete
- The sources of Kotlin
Compiling and running the exercises can be achieved with gradle:
./gradlew run
Then a Micronaut server will start.
- Base address is http://localhost:8080
- Remote port is
8000
- Health check is http://localhost:8080/health
- OpenAPI file is http://localhost:8080/openapi/kotlin-training-1.0.yml
Fill the HelloController
class to make it answer the following JSON:
{
"content": "Hello world!"
}
Create a new /companies
POST endpoint that will take a JSON like
{
"name": "Antaes"
}
and return the following response:
{
"self": "http://localhost:8080/companies/1",
"name": "Antaes"
}
Create a new /companies
GET endpoint that will return the location of recorded companies:
[
"http://localhost:8080/companies/1",
"http://localhost:8080/companies/2"
]
Create a new /companies/{id}
PUSH endpoint that will update the corresponding company data and returns it:
{
"name": "Antaes Consulting S.A.",
"creationYear": 2007
}
Response:
{
"self": "http://localhost:8080/companies/1",
"name": "Antaes Consulting S.A.",
"creationYear": 2007
}