Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Working with Java & Kotlin

Working with Java & Kotlin

The presentation shows how Kotlin fits in the Java Ecosystem while demonstrating some basic language features using sample code: console, spring boot and android app

Charles Muchene

March 02, 2019
Tweet

More Decks by Charles Muchene

Other Decks in Technology

Transcript

  1. Agenda • What is Kotlin? • Kotlin - Java interoperability

    • Kotlin on Spring • Kotlin on Android
  2. Person Controller @RestController class PersonController(private val personRepository: PersonRepository) { @GetMapping("/person")

    fun readAll() = personRepository.findAll() @GetMapping("/person/{id}") fun readOne(@PathVariable id: Long) = personRepository.findById(id) }
  3. Main Activity class MainActivity : AppCompatActivity() { private lateinit var

    viewModel: CountryViewModel private var countryAdapter = CountryAdapter() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) ... } ...
  4. Country Details ViewModel class CountryDetailsViewModel : ViewModel() { fun getDetails(country:

    Country): String = with(country) { """ Native Name: $nativeName Demonym: ${demonym.orDash} Population: ${String.format("%,d", population)} Language(s): ${languages.joinToString(transform = Language::toString)} Currency: ${currencies.joinToString(transform = Currency::toString)} Timezone(s): ${timezones.joinToString()} """.trimIndent() } }