This document discusses various aspects of control flow and objects in Kotlin including:
- Constructors can be declared as part of a class and initialize properties. Initialization blocks and secondary constructors are also supported.
- Objects can be used to create singletons and anonymous classes. Companion objects allow associating static-like functionality with a class.
- Control flow avoids goto and supports return, break, continue with labels. Conditional expressions like if and when can be used anywhere expressions are expected.
- Basic control structures like for loops, while loops, and try/catch work similarly to Java but offer additional functionality like expression bodies.
Kotlin For Android - Basics (part 1 of 7)Gesh Markov
This presentation is part of a workshop series.
In this section you will learn how to create classes, interfaces, and functions. At the end you should be able to write a very simple Kotiln class.
License:
This presentation is licensed under the Creative Commons, No Derivatives, Version 3.0 US: https://creativecommons.org/licenses/by-nd/3.0/us/legalcode
Introduction to kotlin and OOP in Kotlinvriddhigupta
Now that the Android Campaign has started, let’s make a few things clear
NO PREREQUISITES to attend the jams! Absolutely none. Just come with a curious mind and we will handle the rest ♂️♀️
The first study jam which will be conducted on 3rd December, Friday at 6.30 PM will cover half of Unit 1 which is about learning the Kotlin language
And finally, about making the application, we will be making it with you in the upcoming study jams so no matter how much of a beginner you are, you will have made something in the end!
With the announcement on officially supporting Kotlin for Android, this presentation tries to compare Java and Kotlin to encourage people to switch to Kotlin
Kotlin For Android - Basics (part 1 of 7)Gesh Markov
This presentation is part of a workshop series.
In this section you will learn how to create classes, interfaces, and functions. At the end you should be able to write a very simple Kotiln class.
License:
This presentation is licensed under the Creative Commons, No Derivatives, Version 3.0 US: https://creativecommons.org/licenses/by-nd/3.0/us/legalcode
Introduction to kotlin and OOP in Kotlinvriddhigupta
Now that the Android Campaign has started, let’s make a few things clear
NO PREREQUISITES to attend the jams! Absolutely none. Just come with a curious mind and we will handle the rest ♂️♀️
The first study jam which will be conducted on 3rd December, Friday at 6.30 PM will cover half of Unit 1 which is about learning the Kotlin language
And finally, about making the application, we will be making it with you in the upcoming study jams so no matter how much of a beginner you are, you will have made something in the end!
With the announcement on officially supporting Kotlin for Android, this presentation tries to compare Java and Kotlin to encourage people to switch to Kotlin
If any class have multiple functions with same names but different parameters then they are said to be overloaded. Function overloading allows you to use the same name for different functions, to perform, either same or different functions in the same class.
If you have to perform one single operation but with different number or types of arguments, then you can simply overload the function.
Halogen is a popular choice for building front-end user-interfaces with PureScript. Often described as a purely functional version of React, Halogen allows building user-interfaces by composing declarative, self-contained components, including effectful components those built from third-party Javascript libraries.
In this presentation, John presents a high-level summary of where Halogen has come from, how it works right now, and what are the main drawbacks to both FRP and React. John then suggests that incremental computation should be the foundation for the next major version of Halogen, and sketches out a possible way of achieving that in a declarative fashion.
Kotlin For Android - Functions (part 3 of 7)Gesh Markov
This presentation is part of a workshop series.
In this section you will learn about operators, inlining, a little bit about generics, named parameters, lambdas and closures, obtaining references to functions and passing them to other functions, and higher-order functions.
License:
This presentation is licensed under the Creative Commons, No Derivatives, Version 3.0 US: https://creativecommons.org/licenses/by-nd/3.0/us/legalcode
If any class have multiple functions with same names but different parameters then they are said to be overloaded. Function overloading allows you to use the same name for different functions, to perform, either same or different functions in the same class.
If you have to perform one single operation but with different number or types of arguments, then you can simply overload the function.
Halogen is a popular choice for building front-end user-interfaces with PureScript. Often described as a purely functional version of React, Halogen allows building user-interfaces by composing declarative, self-contained components, including effectful components those built from third-party Javascript libraries.
In this presentation, John presents a high-level summary of where Halogen has come from, how it works right now, and what are the main drawbacks to both FRP and React. John then suggests that incremental computation should be the foundation for the next major version of Halogen, and sketches out a possible way of achieving that in a declarative fashion.
Kotlin For Android - Functions (part 3 of 7)Gesh Markov
This presentation is part of a workshop series.
In this section you will learn about operators, inlining, a little bit about generics, named parameters, lambdas and closures, obtaining references to functions and passing them to other functions, and higher-order functions.
License:
This presentation is licensed under the Creative Commons, No Derivatives, Version 3.0 US: https://creativecommons.org/licenses/by-nd/3.0/us/legalcode
While Google is adding Kotlin as an official Android language, we're also expanding our research on this language. It’s developed by JetBrains, and the fact that these are the people behind a suite of IDEs, such as IntelliJ and ReSharper, really shines through in Kotlin. It’s pragmatic and concise and makes coding a satisfying and efficient experience.
Although Kotlin compiles to both JavaScript and soon machine code, I’ll focus on its prime environment, the JVM.
Please see my presentation to learn more!
SpringOne Platform 2017
Sébastien Deleuze, Pivotal
"In this new talk, I will explain why Spring <3 Kotlin and how you can leverage Spring official support for Kotlin (in Framework, Boot, Data) to build your next Spring project more efficiently and with more pleasure.
I will describe gradually how you can transform your Spring Boot 1.0 Java + Javascript project with into a Spring Boot 2.0 pure Kotlin project running on top of the new WebFlux functional web framework."
this talk is about some of the features of Javascript that are not always good understood by developers like me (that are mainly back-end and work mainly in c# or Java)
In this talk I presented three important topics in Kotlin Standard Library: Scope Functions (let, apply, also, run and with); Annotations (Deprecated, Experimental, Jvm*, DslMarker); and Delegates (lazy, vetoable, observable)
Scala is a programming language that mixes object oriented and functional programming in a powerful and flexible way. While it can not be considered as a mainstream language, it has seen a growing adoption trend.An important ingredient for this diffusion is its complete interoperability with Java and the fact that it runs on a solid platform such as the JVM.
It is currently the 4th most loved programming language and the 2nd top paying technology of 2016 (StackOverflow Developers Survey).
These slides have been used for a 4h seminar at the University of Cagliari the 17th of December 2016
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteGoogle
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-pilot-review/
AI Pilot Review: Key Features
✅Deploy AI expert bots in Any Niche With Just A Click
✅With one keyword, generate complete funnels, websites, landing pages, and more.
✅More than 85 AI features are included in the AI pilot.
✅No setup or configuration; use your voice (like Siri) to do whatever you want.
✅You Can Use AI Pilot To Create your version of AI Pilot And Charge People For It…
✅ZERO Manual Work With AI Pilot. Never write, Design, Or Code Again.
✅ZERO Limits On Features Or Usages
✅Use Our AI-powered Traffic To Get Hundreds Of Customers
✅No Complicated Setup: Get Up And Running In 2 Minutes
✅99.99% Up-Time Guaranteed
✅30 Days Money-Back Guarantee
✅ZERO Upfront Cost
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
Launch Your Streaming Platforms in MinutesRoshan Dwivedi
The claim of launching a streaming platform in minutes might be a bit of an exaggeration, but there are services that can significantly streamline the process. Here's a breakdown:
Pros of Speedy Streaming Platform Launch Services:
No coding required: These services often use drag-and-drop interfaces or pre-built templates, eliminating the need for programming knowledge.
Faster setup: Compared to building from scratch, these platforms can get you up and running much quicker.
All-in-one solutions: Many services offer features like content management systems (CMS), video players, and monetization tools, reducing the need for multiple integrations.
Things to Consider:
Limited customization: These platforms may offer less flexibility in design and functionality compared to custom-built solutions.
Scalability: As your audience grows, you might need to upgrade to a more robust platform or encounter limitations with the "quick launch" option.
Features: Carefully evaluate which features are included and if they meet your specific needs (e.g., live streaming, subscription options).
Examples of Services for Launching Streaming Platforms:
Muvi [muvi com]
Uscreen [usencreen tv]
Alternatives to Consider:
Existing Streaming platforms: Platforms like YouTube or Twitch might be suitable for basic streaming needs, though monetization options might be limited.
Custom Development: While more time-consuming, custom development offers the most control and flexibility for your platform.
Overall, launching a streaming platform in minutes might not be entirely realistic, but these services can significantly speed up the process compared to building from scratch. Carefully consider your needs and budget when choosing the best option for you.
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Crescat
Crescat is industry-trusted event management software, built by event professionals for event professionals. Founded in 2017, we have three key products tailored for the live event industry.
Crescat Event for concert promoters and event agencies. Crescat Venue for music venues, conference centers, wedding venues, concert halls and more. And Crescat Festival for festivals, conferences and complex events.
With a wide range of popular features such as event scheduling, shift management, volunteer and crew coordination, artist booking and much more, Crescat is designed for customisation and ease-of-use.
Over 125,000 events have been planned in Crescat and with hundreds of customers of all shapes and sizes, from boutique event agencies through to international concert promoters, Crescat is rigged for success. What's more, we highly value feedback from our users and we are constantly improving our software with updates, new features and improvements.
If you plan events, run a venue or produce festivals and you're looking for ways to make your life easier, then we have a solution for you. Try our software for free or schedule a no-obligation demo with one of our product specialists today at crescat.io
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
Transform Your Communication with Cloud-Based IVR SolutionsTheSMSPoint
Discover the power of Cloud-Based IVR Solutions to streamline communication processes. Embrace scalability and cost-efficiency while enhancing customer experiences with features like automated call routing and voice recognition. Accessible from anywhere, these solutions integrate seamlessly with existing systems, providing real-time analytics for continuous improvement. Revolutionize your communication strategy today with Cloud-Based IVR Solutions. Learn more at: https://thesmspoint.com/channel/cloud-telephony
Artificia Intellicence and XPath Extension FunctionsOctavian Nadolu
The purpose of this presentation is to provide an overview of how you can use AI from XSLT, XQuery, Schematron, or XML Refactoring operations, the potential benefits of using AI, and some of the challenges we face.
Mobile App Development Company In Noida | Drona InfotechDrona Infotech
Looking for a reliable mobile app development company in Noida? Look no further than Drona Infotech. We specialize in creating customized apps for your business needs.
Visit Us For : https://www.dronainfotech.com/mobile-application-development/
E-commerce Application Development Company.pdfHornet Dynamics
Your business can reach new heights with our assistance as we design solutions that are specifically appropriate for your goals and vision. Our eCommerce application solutions can digitally coordinate all retail operations processes to meet the demands of the marketplace while maintaining business continuity.
Utilocate offers a comprehensive solution for locate ticket management by automating and streamlining the entire process. By integrating with Geospatial Information Systems (GIS), it provides accurate mapping and visualization of utility locations, enhancing decision-making and reducing the risk of errors. The system's advanced data analytics tools help identify trends, predict potential issues, and optimize resource allocation, making the locate ticket management process smarter and more efficient. Additionally, automated ticket management ensures consistency and reduces human error, while real-time notifications keep all relevant personnel informed and ready to respond promptly.
The system's ability to streamline workflows and automate ticket routing significantly reduces the time taken to process each ticket, making the process faster and more efficient. Mobile access allows field technicians to update ticket information on the go, ensuring that the latest information is always available and accelerating the locate process. Overall, Utilocate not only enhances the efficiency and accuracy of locate ticket management but also improves safety by minimizing the risk of utility damage through precise and timely locates.
Atelier - Innover avec l’IA Générative et les graphes de connaissancesNeo4j
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Allez au-delà du battage médiatique autour de l’IA et découvrez des techniques pratiques pour utiliser l’IA de manière responsable à travers les données de votre organisation. Explorez comment utiliser les graphes de connaissances pour augmenter la précision, la transparence et la capacité d’explication dans les systèmes d’IA générative. Vous partirez avec une expérience pratique combinant les relations entre les données et les LLM pour apporter du contexte spécifique à votre domaine et améliorer votre raisonnement.
Amenez votre ordinateur portable et nous vous guiderons sur la mise en place de votre propre pile d’IA générative, en vous fournissant des exemples pratiques et codés pour démarrer en quelques minutes.
Zoom is a comprehensive platform designed to connect individuals and teams efficiently. With its user-friendly interface and powerful features, Zoom has become a go-to solution for virtual communication and collaboration. It offers a range of tools, including virtual meetings, team chat, VoIP phone systems, online whiteboards, and AI companions, to streamline workflows and enhance productivity.
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
3. classes
BASIC SYNTAX
y/kotlin-workbook
interface Runnable {
fun run()
}
interface RepeatingRunnable : Runnable {
fun run(times: Int) {
(1..times).forEach { run() }
}
}
open class Greeting : Runnable {
override fun run() = println("Hi!")
}
class RepeatingGreeting : Greeting(), RepeatingRunnable
RepeatingGreeting().run(3)
4. ● One primary constructor as part of class declaration
○ Declare property visibility and default values in the
parameter list
constructors
OBJECTS AND FLOW
y/kotlin-workbook
class Person(
val name: String = "John",
private var age: Int
)
5. ● One primary constructor as part of class declaration
○ Declare property visibility and default values in the
parameter list
● Initialization blocks - init
constructors
OBJECTS AND FLOW
y/kotlin-workbook
class Person(
val name: String = "John",
private var age: Int
){
init {
// Initialize things here...
}
}
6. ● One primary constructor as part of class declaration
○ Declare property visibility and default values in the
parameter list
● Initialization blocks - init
● Optional secondary constructors
● Property initialization
constructors
OBJECTS AND FLOW
y/kotlin-workbook
class Person(
val name: String = "John",
private var age: Int
){
var hairColor: Color = Color.BLACK
init {
// Initialize things here...
}
constructor(age: Int, hairColor: Color): this(age = age){
this.hairColor = hairColor
}
}
8. object
OBJECTS AND FLOW
y/kotlin-workbook
● Used to create anonymous inner classes and singletons
● Can have static methods in the JVM
● Can have static fields in the JVM
● Every class can have a companion object
● Cannot inherit from object
○ object can inherit and extend though
9. object
OBJECTS AND FLOW
y/kotlin-workbook
object Foo {
val BAR = "BAR"
fun hi() = "hi"
}
// kotlin
val bar = Foo.BAR
val foo = Foo.hi()
// java
String bar = Foo.INSTANCE.BAR;
String foo = Foo.INSTANCE.hi();
10. object
OBJECTS AND FLOW
y/kotlin-workbook
object Foo {
const val BAR = "BAR"
@JvmStatic fun hi() = "hi"
}
// kotlin
val bar = Foo.BAR
val foo = Foo.hi()
// java
String bar = Foo.INSTANCE.BAR;
String foo = Foo.INSTANCE.hi();
// java improved interop
String bar = Foo.BAR;
String foo = Foo.hi();
11. companion object
advanced
OBJECTS AND FLOW
y/kotlin-workbook
UserRepo.intance() // returns the real repo
BizRepo.intance() // returns the real repo
UserRepo.mock = mock(UserRepo)
BizRepo.mock = mock(BizRepo)
UserRepo.intance() // returns the mock repo
BizRepo.intance() // returns the mock repo
UserRepo.mock = null
BizRepo.mock = null
UserRepo.intance() // returns the real repo
BizRepo.intance() // returns the real repo
12. companion object
advanced
OBJECTS AND FLOW
y/kotlin-workbook
interface Factory<T: Any> {
var mock: T?
fun instance(): T
}
UserRepo.intance() // returns the real repo
BizRepo.intance() // returns the real repo
UserRepo.mock = mock(UserRepo)
BizRepo.mock = mock(BizRepo)
UserRepo.intance() // returns the mock repo
BizRepo.intance() // returns the mock repo
UserRepo.mock = null
BizRepo.mock = null
UserRepo.intance() // returns the real repo
BizRepo.intance() // returns the real repo
13. companion object
advanced
OBJECTS AND FLOW
y/kotlin-workbook
interface Factory<T: Any> {
var mock: T?
fun instance(): T
}
open class Provider<T: Any>(init: () -> T): Factory<T> {
override var mock: T? = null
private val instance: T by lazy(init)
override fun instance() = mock ?: instance
}
UserRepo.intance() // returns the real repo
BizRepo.intance() // returns the real repo
UserRepo.mock = mock(UserRepo)
BizRepo.mock = mock(BizRepo)
UserRepo.intance() // returns the mock repo
BizRepo.intance() // returns the mock repo
UserRepo.mock = null
BizRepo.mock = null
UserRepo.intance() // returns the real repo
BizRepo.intance() // returns the real repo
14. companion object
advanced
OBJECTS AND FLOW
y/kotlin-workbook
interface Factory<T: Any> {
var mock: T?
fun instance(): T
}
open class Provider<T: Any>(init: () -> T): Factory<T> {
override var mock: T? = null
private val instance: T by lazy(init)
override fun instance() = mock ?: instance
}
class UserRepo {
companion object : Provider<UserRepo>({ UserRepo() })
}
class BizRepo {
companion object : Provider<BizRepo>({ BizRepo() })
}
UserRepo.intance() // returns the real repo
BizRepo.intance() // returns the real repo
UserRepo.mock = mock(UserRepo)
BizRepo.mock = mock(BizRepo)
UserRepo.intance() // returns the mock repo
BizRepo.intance() // returns the mock repo
UserRepo.mock = null
BizRepo.mock = null
UserRepo.intance() // returns the real repo
BizRepo.intance() // returns the real repo
16. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
fun foo() {
listOf(1, 2, 3, 4, 5).forEach {
if (it == 3) return
print(it)
}
println(" this is unreachable")
}
● No goto
● return, break and continue
17. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
fun foo() {
listOf(1, 2, 3, 4, 5).forEach {
if (it == 3) return
print(it)
}
println(" this is unreachable")
}
// 12
● No goto
● return, break and continue
18. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
fun foo() {
listOf(1, 2, 3, 4, 5).forEach {
if (it == 3) return@forEach
print(it)
}
println(" this is reachable")
}
● No goto
● return, break and continue can use labels
19. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
fun foo() {
listOf(1, 2, 3, 4, 5).forEach {
if (it == 3) return@forEach
print(it)
}
println(" this is reachable")
}
// 1245 this is reachable
● No goto
● return, break and continue can use labels
20. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
fun foo() {
listOf(1, 2, 3, 4, 5).forEach loop@{
if (it == 3) return@loop
print(it)
}
println(" this is reachable")
}
// 1245 this is reachable
● No goto
● return, break and continue can use labels
21. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
fun foo() {
listOf(1, 2, 3, 4, 5).run { forEach {
if (it == 3) return@run
print(it)
}}
println(" this is reachable")
}
// 12 this is reachable
● No goto
● return, break and continue can use labels
22. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
fun foo() {
for (int in listOf(1, 2, 3, 4, 5)) {
if (int == 3) break
print(int)
}
println(" this is reachable")
}
● No goto
● return, break and continue can use labels
● for loop - no parameterized for(;;)
23. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
● No goto
● return, break and continue can use labels
● for loop - no parametrized for(;;)
● while - same as java
24. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
return if (isJvmRuntime) {
RuntimeEnvironment.application
} else {
InstrumentationRegistry.getContext()
}
● No goto
● return, break and continue can use labels
● for loop - no parametrized for(;;)
● while - same as java
● if - same as java, can be used as an expression
25. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
return when (isJvmRuntime) {
true -> RuntimeEnvironment.application
else -> InstrumentationRegistry.getContext()
}
● No goto
● return, break and continue can use labels
● for loop - no parametrized for(;;)
● while - same as java
● if - same as java, can be used as an expression
● when - replaces switch from java, can be used as expr.
26. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
val z = when {
x.isOdd() -> "x is odd"
y.isEven() -> "y is even"
else -> "x is funny, y is cool"
}
● No goto
● return, break and continue can use labels
● for loop - no parametrized for(;;)
● while - same as java
● if - same as java, can be used as an expression
● when - replaces switch from java, can be used as expr.
27. Control Flow
OBJECTS AND FLOW
y/kotlin-workbook
val isJvmRuntime = try {
Class.forName("org.robolectric.RuntimeEnvironment")
true
} catch (notFound: ClassNotFoundException) {
false
}
● No goto
● return, break and continue can use labels
● for loop - no parametrized for(;;)
● while - same as java
● if - same as java, can be used as an expression
● when - replaces switch from java, can be used as expr.
● try catch - same as java, can be used as an expression
Continue where we left off - deep dive on constructors
Any number of init blocks
Nonnull properties outside the primary constructor must be initialized by the end of the block
Secondary constructors must delegate to primary constructor if declared
Deep dive on constructors
Anonymous inner class is an object expression, singleton is an object declaration
Is as close to having static as kotlin allows
still instance members of real objects
Kotlin looks just like you remember with java statics
Not super friendly interop
Return real repo only if mock is not set
Painful to do in Java without inheritance, must implement for both
Talk about generics
Most permissive generic is Any?
Called local return, uses an implicit label
This return is equivalent to a continue, and only 3 will not be printed
Called local return, uses an implicit label
This return is equivalent to a continue, and only 3 will not be printed
Can explicitly declare the labels
Same as above slide
Can use .withIndex() and destructure: for ((index, value) in array.withIndex())
Compiles down to if/else blocks
Only need else in expression and if you use enums/sealed class it isn’t needed
No fall through
Not parameterized evaluates each and evaluates first true
Can use blocks of code
ALMOST END OF SLIDES - NEXT SLIDE IS LAST - Q&A STARTS