Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Programming Kotlin
  • Table Of Contents Toc
  • Feedback & Rating feedback
Programming Kotlin

Programming Kotlin

By : Samuel, Bocutiu
3.4 (7)
close
close
Programming Kotlin

Programming Kotlin

3.4 (7)
By: Samuel, Bocutiu

Overview of this book

Quickly learn the fundamentals of the Kotlin language and see it in action on the web. Easy to follow and covering the full set of programming features, this book will get you fluent in Kotlin for Android.
Table of Contents (14 chapters)
close
close

Optionals


Throughout the previous sections, we have discussed Kotlin's approach to null safety. But this is not the only approach. Languages such as Haskell have provided an alternative for many years. In Haskell's case, this is called the Maybe type. In Scala there is something similar called the Option type, and in the most recent version of Java (at the time of writing, Java 8) there is Optional.

All of these types-Maybe, Option, Optional-aim to do the same thing. That is, they use a type to indicate that a function or expression may or may not return a value.

In Functional programming. they are most often an algebraic data type with two values-one that represents a value and one that represents the lack of a value. In Haskell they are called Just and Nothing. In Scala they are called Some and None. In Java only a single type is used.

For the rest of this section, we will focus on the Java Optional. Remember, though, that this will not be available to you if you are not compiling on Java...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY