Skip to content

vpetreski/playground.kt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Kotlin Playground

  • Main.kt - no package; no semicolon

Basics

  • Hello1, Hello2 - top-level function; main with args & no args; string templates, Array syntax & wrappers; if expression
  • Variables - read-only & mutable variables; type inference
  • Functions1, Functions2, FunctionsJ - expression body; Unit; top-level, member, local; calling from Java; named & default args; @JvmOverloads

Control Structures

Extensions

  • ExtensionFunctions - extension functions, examples, standard library
  • SumExtensionFunction - small task to create extension function
  • CallingExtensions - how extensions interact with inheritance and can extensions hide members
  • With extensions, we can keep our classes and interfaces APIs minimal and write everything else as extension, but keep them close together.
  • We can use extensions when we don't control some class or interface, many existing Java libraries have companion libraries with a number of extensions.

Nullability

Functional Programming

Properties

OOP

  • Defaults are different in Kotlin - public and final by default
  • If you want to make it non-final, you have to set it explicitly as open
  • No package private visibility in Kotlin, use internal for that - visible in module
  • Module is a set of Kotlin files compiled together (IntelliJ IDEA, Maven project, Gradle source set)
  • So we have there modifiers: public, protected private, internal. Then: final, open, abstract. Also override.
  • In Kotlin we can have multiple classes in the same file, while in Java we prefer one class per file. One file can additionally contain multiple top-level functions, properties, etc.
  • In Kotlin, package doesn't have to correspond to directory structure - we can have org.company.store package, but it can be physically located in top level store folder for example. Good recommendatioon is to simply omit org.company or org.company.project from directory structure.
  • CtxInherit - constructors, inheritance syntax
  • ClassModifiers - class modifiers, enum, data, equality, sealed, inner, nested, class delegation
  • Objects - objects, object declaration, object expression, companion object, "static" members
  • Constants
  • Generics

Conventions

Inline Functions

  • LibraryFunctions - by inlining, library functions look like built-in language construct
  • Inline - the power of inline

Mix

  • Sequences - collection vs sequences, how to create mix...
  • LambdaWithReceiver - lambda with receiver
  • Types - types, type hierarchy, Any, Unit, Nothing, nullable types, collection types

Other

About

Kotlin Playground

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published