Skip to workspace
Kotlin Lab

Java → Kotlin/JVM

Think in Kotlin.

You already know Java. Learn where Kotlin changes the decision, then write the code yourself.

Index users by ID
Java 25
users.stream().collect(toMap(
    User::id, identity(),
    (prior, latest) -> latest
))
Kotlin
users.associateBy { it.id }
Duplicate ID? Both keep the last profile.

Curriculum

Learning path

26 chapters · 78 questions

Everyday Kotlin

Make everyday Java decisions in Kotlin.

7 chapters
  1. 01Choose val or varTrack a warehouse balance without losing intermediate stock levels.
  2. 02Price a delivery with whenPut overlapping delivery rules in the order the business promises.
  3. 03Compare parcel identitiesSeparate value equality, reference identity, and missing identifiers.
  4. 04Narrow a scanner payloadUse a guard to make a nullable, unknown value safe to inspect.
  5. 05Resolve a display nameCombine safe calls and Elvis without loading an unnecessary fallback.
  6. 06Give a retry policy defaultsExpress a dependent default once and let callers override just the decision they own.
  7. 07Format a transit ETAPlace identifiers, expressions, and literal suffixes in a string template.

Working with data

Choose collection operations that preserve your contract.

8 chapters
  1. 01Index users by IDChoose what survives when two directory updates have the same key.
  2. 02Freeze the dispatch queueDistinguish a read-only reference from a snapshot of a mutable collection.
  3. 03Revise a release ticketCopy a value with one changed field and keep the original ticket usable.
  4. 04Import valid quantitiesUse a nullable transformation when an invalid row may disappear.
  5. 05Select exactly one routeDistinguish a first match from a unique match before choosing a terminal operation.
  6. 06Count orders by depotDecide whether each group needs its members or just a count.
  7. 07Stop searching once seats fillUse a lazy pipeline when the number of predicate calls is observable.
  8. 08Put a badge on a contactUse an extension for display formatting while making subtype decisions explicit.

Designing Kotlin APIs

Make your types communicate how an API should be used.

6 chapters
  1. 01Choose a scope functionChoose which job a caller receives when saving a configured draft produces a normalized copy.
  2. 02Render every response stateMake adding a network outcome a compiler-visible UI change.
  3. 03Pass a companion as a factoryLet a type own validation and supply a parser wherever a decoder is required.
  4. 04Decorate a price bookChoose which operations to forward when a wrapper changes the price of an item.
  5. 05Connect producers and consumersLet a feed of express parcels write to an archive that accepts any object.
  6. 06Return a booking refusalSeparate a recoverable customer choice from a broken inventory precondition.

Kotlin on the JVM

Work across language boundaries and concurrent lifetimes.

5 chapters
  1. 01Read a Java platform typeGive a legacy setting three meanings: absent, disabled, or configured.
  2. 02Keep Java call sites compilingExpose Kotlin defaults through the JVM methods that Java clients actually call.
  3. 03Cancel an obsolete searchKeep transport recovery from publishing stale results after cancellation.
  4. 04Give concurrent work an ownerStart two independent lookups together and end both with the departure-board request.
  5. 05Collect a cold Flow on demandRead enough sensor samples to fill an alert panel and release the upstream producer.