filmov
tv
Programming Tutorial Bits: Kotlin Data Classes

Показать описание
Programming Tutorial Bits: Kotlin Data Classes
In this video we will learn:
- How to use data classes in Kotlin.
- How to decompile Kotlin code to understand what it provides
- What Kotlin improves on from Java with data classes
- We will also touch on Nullable and Non-Nullable types and what happens when
we try to call a non Nullable type with null form Java (Oh noes!!!)
---------------------------
Clarifications:
---------------------------
Auto Get and Set generation:
- If the member is declared with var and is accessible to class users (not
private etc) you have access to setters and getters
- If it is declared with "val" this NO SETTERS are generated. "val" is
essentially like declaring "final" in Java the world.
- EXPERIMENT AND TRY IT OUT! :)
!! Not-Null assertion operator
I touched a little the not null assertion operator, double exclamation point
"!!" and why you should generally avoid it.
- I highly recommend reserving these to only test (not prod) code. This is
typically a code smell that may indicate you need to refactor.
- If your application ever encounters null with this operator you will get a
null pointer exception
- Failing fast is fine in cases where you never expect null, so there may be
practical production cases for this.
- In practice though, you'll prob find yourself sanitizing using
question mark operator and Elvis "?:" (which I will touch on in a later video)
and probably throwing more specific validation exceptions etc.
---------------------------
Resources:
---------------------------
- Code and exercises from video:
- Kotlin language reference:
- IntelliJ IDE
In this video we will learn:
- How to use data classes in Kotlin.
- How to decompile Kotlin code to understand what it provides
- What Kotlin improves on from Java with data classes
- We will also touch on Nullable and Non-Nullable types and what happens when
we try to call a non Nullable type with null form Java (Oh noes!!!)
---------------------------
Clarifications:
---------------------------
Auto Get and Set generation:
- If the member is declared with var and is accessible to class users (not
private etc) you have access to setters and getters
- If it is declared with "val" this NO SETTERS are generated. "val" is
essentially like declaring "final" in Java the world.
- EXPERIMENT AND TRY IT OUT! :)
!! Not-Null assertion operator
I touched a little the not null assertion operator, double exclamation point
"!!" and why you should generally avoid it.
- I highly recommend reserving these to only test (not prod) code. This is
typically a code smell that may indicate you need to refactor.
- If your application ever encounters null with this operator you will get a
null pointer exception
- Failing fast is fine in cases where you never expect null, so there may be
practical production cases for this.
- In practice though, you'll prob find yourself sanitizing using
question mark operator and Elvis "?:" (which I will touch on in a later video)
and probably throwing more specific validation exceptions etc.
---------------------------
Resources:
---------------------------
- Code and exercises from video:
- Kotlin language reference:
- IntelliJ IDE