Kotlin is all about removing some of the verbosity of Java, so now you can see alternative ways of writing the class you just built—in particular one with almost no code at all!
- [Instructor] Now they're not,…really doing anything that sensible.…So I'm going to remove these.…But I'd like to show you an alternative,…for how we could have created this customer class.…I'm not going to say that this alternative is better,…but I'd like to go through it,…because it will help us understand,…exactly how all these different things,…these fields of constructors,…and edit blocks are really working.…So let's create this as a second class,…within the same file.…And well call this alternative customer.…(typing quickly)…Now in this version the optional field, the address,…I'm going to make that a field within the class,…rather than part of the primary constructor.…
So we're going to have primary constructor,…consisting of the name as a string,…and the age as an integer.…(typing quickly)…And in fact I'll change that to a Var,…so we're doing exactly the same thing.…And then within the code for the class itself,…is where I'm going to define the address.…And I'm going to define this as a Var rather than a Val.…
Author
Released
1/30/2019- Creating a new Kotlin project
- Working with strings
- Data types in Kotlin
- Creating and calling top-level functions
- Creating classes
- Collections
- Throwing exceptions
- Class inheritance
- Java interoperability
- Functional programming
- Using JUnit with Kotlin
Skill Level Intermediate
Duration
Views
Related Courses
-
Kotlin Essential Training
with David Gassner3h 45m Beginner -
Kotlin for Java Developers
with Troy Miles2h 27m Advanced -
Learning Spring with Spring Boot
with Frank P Moley III1h 33m Intermediate -
Spring: Framework In Depth
with Frank P Moley III2h 16m Intermediate
-
1. Introduction
-
Introduction1m 45s
-
What is Kotlin?5m 46s
-
Installing IntelliJ3m 11s
-
Configuring IntelliJ7m 7s
-
-
2. Working with Strings
-
Variable declaration syntax4m 32s
-
Using string templates4m 40s
-
Multiple line strings6m 54s
-
3. Other Variable Types
-
The Int data type2m 11s
-
Other data types6m 18s
-
Casting in Kotlin6m 35s
-
Chapter review1m 17s
-
4. Nullable Variables
-
The Nothing object type3m 8s
-
5. Functions
-
Single expression functions3m 14s
-
6. Classes
-
Secondary constructors5m 20s
-
Alternative class design5m 3s
-
Functions within a class2m 57s
-
Static functions3m 28s
-
Data classes7m 32s
-
7. Practical Exercise 1
-
Explaining the challenge4m 35s
-
Solution walk-through9m 51s
-
-
8. If and Object Equality
-
The let function9m 36s
-
9. Ranges and Looping
-
The while loop1m 25s
-
Looping with a range6m 13s
-
-
10. Collections
-
Mutable lists1m 30s
-
Maps and sets1m 45s
-
Working with arrays4m 16s
-
11. Practical Exercise 2
-
Explaining the challenge7m 10s
-
Solution walk-through8m 46s
-
-
12. Exceptions and the try-catch Block
-
Exceptions are unchecked4m 55s
-
Throwing exceptions4m 45s
-
try as an expression2m 23s
-
-
13. Testing
-
Using JUnit with Kotlin5m 1s
-
Testing for exceptions4m 20s
-
-
14. Polymorphism and Inheritance
-
Class inheritance5m 11s
-
Creating custom exceptions2m 35s
-
Extension functions4m 38s
-
15. Java Interoperability
-
Using data classes1m 21s
-
Using immutable lists2m 17s
-
Exception handling3m 18s
-
Using static functions2m 13s
-
16. Getting Started with Spring Boot
-
A hello world controller3m 33s
-
Overview of the case study1m 42s
-
Adding services4m 13s
-
Posting to a controller5m 3s
-
Dependency injection6m 38s
-
Revisiting backing beans3m 32s
-
17. Functional Programming
-
filter and flatMap3m 46s
-
reduce and fold6m 33s
-
Working with maps3m 14s
-
18. Getting Started with Hibernate
-
19. Practical Exercise 3
-
Solution walk-through2m 33s
-
Mappings between entities7m 33s
-
Upgrading the view11m 25s
-
Solution walk-through9m 4s
-
Solution walk-through4m 21s
-
20. Reflection
-
The concept of reflection7m 20s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Alternative class design