SlideShare a Scribd company logo
Null-safety
val a: String? = null
println(a?.length())
Null-safety
val a: String? = null
println(a?.length())
> null
Null-safety
int length = a != null ? a.length() : -1
Null-safety
int length = a != null ? a.length() : -1
Null check
Null-safety
int length = a != null ? a.length() : -1
Assignmentselector
Null-safety
var length = if (a != null) a.length() else -1
Null-safety
var length = if (a != null) a.length() else -1
Null check
Null-safety
var length = if (a != null) a.length() else -1
Assignmentselector
Null-safety
var length = a?.length() ?: -1
Null-safety
var length = a?.length() ?: -1
Null check
Null-safety
var length = a?.length() ?: -1
Assignmentselector
Smart casts
Smart casts
if (x is String) {
print(x.length())
}
Smart casts
if (x is String) {
print(x.length())
}
Typecheck
Smart casts
if (x is String) {
print(x.length())
}
Smart cast
Smart casts
if (x !is String) {
return
}
print(x.size())
Smart casts
if (x !is String) {
return
}
print(x.size())Type check
Smart casts
if (x !is String) {
return
}
print(x.size())
Smart casts
if (x !is String) {
return
}
print(x.size())
Smart cast
Smart casts
if (x !is String || x.size() == 0) {
return
}
Smart casts
if (x !is String || x.size() == 0) {
return
}
Typecheck
Smart casts
if (x !is String || x.size() == 0) {
return
}
Smart casts
if (x !is String || x.size() == 0) {
return
}
Smart cast
Smart casts
if (x is String && x.size() > 0) {
print(x.size())
}
Smart casts
if (x is String && x.size() > 0) {
print(x.size())
}
Typecheck
Smart casts
if (x is String && x.size() > 0) {
print(x.size())
}
Smart casts
if (x is String && x.size() > 0) {
print(x.size())
}
Smart cast
Smart casts
if (x is String && x.size() > 0) {
print(x.size())
}
Smart cast
Smart casts
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Smart casts
Typecheck
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Smart casts
Smart cast
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Smart casts
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Typecheck
Smart casts
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Smart cast
Smart casts
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Type check
Smart casts
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Smart cast
String templates
String templates
val apples = 4
println("I have " + apples + " apples.")
> I have 4 apples.
String templates
val apples = 4
println("I have $apples apples.")
> I have 4 apples.
> I have 4 apples.
String templates
val apples = 4
val bananas = 3
println("I have $apples apples and " + (apples + bananas) + " fruits.")
> I have 4 apples.
> I have 4 apples.
> I have 4 apples and 7 fruits.
String templates
val apples = 4
val bananas = 3
println("I have $apples apples and ${apples+bananas} fruits.")
> I have 4 apples.
> I have 4 apples and 7 fruits.
> I have 4 apples and 7 fruits.
Range expressions
Range expressions
if (1 <= i && i <= 10) {
println(i)
}
Range expressions
if (1 <= i && i <= 10) {
println(i)
}
if (IntRange(1, 10).contains(i)) {
println(i)
}
Range expressions
if (1 <= i && i <= 10) {
println(i)
}
if (1.rangeTo(10).contains(i)) {
println(i)
}
Range expressions
if (1 <= i && i <= 10) {
println(i)
}
if (i in 1..10 ) {
println(i)
} Range operator
Range expressions
for (i in 1..4) {
print(i)
}
> 1234
Range expressions
for (i in 1..4 step 2) {
print(i)
}
> 1234
> 13
Range expressions
for (i in 4 downTo 1 step 2) {
print(i)
}
> 1234
> 13
> 42
Range expressions
for (i in 1.0..2.0) {
print("$i ")
}
> 13
> 42
> 1.0 2.0
Range expressions
for (i in 1.0..2.0 step 0.3) {
print("$i ")
}
> 42
> 1.0 2.0
> 1.0 1.3 1.6 1.9
Lab 1
Foo Corporation needs a program to calculate how much to pay their hourly employees. The US Department
of Labor requires that employees get paid time and a half for any hours over 40 that they work in a single
week. For example, if an employee works 45 hours, they get 5 hours of overtime, at 1.5 times their base pay.
The State of Massachusetts requires that hourly employees be paid at least $8.00 an hour. Foo Corp requires
that an employee not work more than 60 hours in a week.
• Rules
• An employee gets paid (hours worked) × (base pay), for each hour up to 40 hours.
• For every hour over 40, they get overtime = (base pay) × 1.5.
• The base pay must not be less than the minimum wage ($8.00 an hour). If it is, print an error.
• If the number of hours is greater than 60, print an error message.
Write a method that takes the base pay and hours worked as parameters, and prints the total pay
or an error. Write a main method that calls this method for each of these employees:
Base Pay Hours Worked
Employee 1 $7.50 35
Employee 2 $8.20 47
Employee 3 $10.00 73
Lab 2
A group of ITI friends decide to run a Marathon. Their names and times (in minutes) are below:
Name Time (minutes)
Ahmed 341
Mohamed 273
Ismail 278
Hend 329
Aly 445
Hossam 402
Ola 388
Alaa 275
Basma 243
Mina 334
Nada 412
Saad 393
• Find the fastest runner. Print the name and his/her time (in minutes).
• Optional: Find the second fastest runner. Print the name and his/her time (in minutes).
Lab 3
• Create an Android a simple app with two buttons, one to count and
one to show a toast.
Lab 4
• Create an Android UI with one text field, centered at the top of the screen, and
one button. The text field will initially display the text Tap to Change Color.
• Every time you tap the button, you will generate a random color using RGB
values, change the text to that color, and display the values for the color in the
following format (assuming you are displaying a light grey with values
100/100/100): COLOR: 100r, 100g, 100b.
Lab 5
• Battery Status App
• Create an Android App that displays a colored
bar to display the battery's status.
• Display a battery drawable as follows:
0-25% - Red (battery low)
>25% <80% - Yellow (battery medium)
>80% - Green (battery good)
When expression
When expression
• When expression is similar to switch/case in Java,
but far more powerful.
When expression
when (argument) {
match1 -> fun1()
match2 -> fun2()
else -> fun3()
}
When expression
when (argument) {
m a t c h 1 - > f u n 1 ( )
m a t c h 2 - > f u n 2 ( )
e l s e - > f u n 3 ( )
}
Can be anything
When expression
( a r g u m e n t )
Match1 -> fun1()
match2 -> fun2()
e l s e - > f u n 3 ( )
}
Can be anything
When expression
var result: Int = when (argument) {
m a t c h 1 - > f u n 1 ( )
m a t c h 2 - > f u n 2 ( )
e l s e - > f u n 3 ( )
}
Can return result
When expression
var result: Int = when (argument) {
match1 -> fun1()
match2 -> fun2()
else -> fun3()
}
When expression
override fun onCreateViewHolder(g: ViewGroup, type: Int) {
when (type) {
TYPE_TITLE -> TitleViewHolder(g)
TYPE_DESCRIPTION -> DescriptionViewHolder(g))
}
return null
}
When expression
o v e r r i d e f u n o n C r e a t e V i e w H o l d e r ( g : V i e w G r o u p ,
t y p e : I n t ) {
when (type) {
T Y P E _ T I T L E - > T i t l e V i e w H o l d e r ( g )
T Y P E _ D E S C R I P T I O N - >
D e s c r i p t i o n V i e w H o l d e r ( g ) )
}
r e t u r n n u l l
}
Can be placed after a = symbol
When expression
override fun onCreateViewHolder(g: ViewGroup, type: Int) = when (type) {
T Y P E _ T I T L E - > T i t l e V i e w H o l d e r ( g )
T Y P E _ D E S C R I P T I O N - >
D e s c r i p t i o n V i e w H o l d e r ( g ) )
e l s e - > n u l l
}
When expression
override fun onCreateViewHolder(g: ViewGroup, type: Int) = when (type) {
TYPE_TITLE -> TitleViewHolder(g)
TYPE_DESCRIPTION -> DescriptionViewHolder(g)
else -> null
}
When expression
override fun getItemViewType(index: Int) = when (dataList[index]) {
is Title -> TYPE_TITLE
is Description -> TYPE_DESCRIPTION
else -> TYPE_UNDEFINED
}
When expression
override fun getItemViewType(index: Int) = when (dataList[index]) {
is Title -> TYPE_TITLE
is Description -> TYPE_DESCRIPTION
else -> TYPE_UNDEFINED
}
Type checks possible
When expression
override fun getItemViewType(index: Int) = when (dataList[index]) {
is Title -> TYPE_TITLE
is Description -> TYPE_DESCRIPTION
else -> TYPE_UNDEFINED
}
When expression
override fun onBindViewHolder(viewHolder: ViewHolder, index: Int) {
val displayable: Displayable = dataList[index]
when (displayable) {
is Title -> initTitle(viewHolder, displayable)
is Description -> initDescription(viewHolder, displayable)
}
}
When expression
o v e r r i d e f u n o n B i n d V i e w H o l d e r ( v i e w H o l d e r : V i e w H o l d e r , i n d e x : I n t ) {
v a l d i s p l a y a b l e : D i s p l a y a b l e = d a t a L i s t [ i n d e x ]
W h e n ( d i s p l a y a b l e ) {
is Title -> initTitle(viewHolder, displayable)
is Description -> initDescription(viewHolder, displayable)
}
}
Smart cast
let, apply, use, with
let, apply, use, with
• Higher-order functions - function that takes
functions as parameters, or returns a function.
let (scope function)
/**
* Calls the specified function [block] with `this` value as
* its argument and returns its result.
*/
public inline fun <T, R> T.let(block: (T) -> R): R = block(this)
let
Preferences.getUser().let {
showUserName(it.name)
showUserEmail(it.email)
}
let
Preferences.getUser().let {
showUserName(it.name)
showUserEmail(it.email)
}
Refers to user object
let
Preferences.getUser().let {
showUserName(it.name)
showUserEmail(it.email)
}
Variable visibility scope
let
Preferences.getUser()?.let {
showUserName(it.name)
showUserEmail(it.email)
}
Only execute if user is not null
let
Preferences.getUser()?.let {
showUserName(it.name)
showUserEmail(it.email)
}
use (try with resources function)
/**
* Executes the given [block] function on this resource and then
* closes it down correctly whether an exception is thrown or not.
*/
public inline fun <T : Closeable, R> T.use(block: (T) -> R): R {
var closed = false
try {
return block(this)
} catch (e: Exception) {
// ommitted
} finally {
if (!closed) { close()
}
}
}
use
fun countUsers(): Long {
val database = openDatabase()
val result = database.count("users")
database.close()
return result
}
use
fun countUsers() = openDatabase().use { it.count("users") }
Automatically close
database
fun countUsers() = openDatabase().use { it.count("users") }
Refers to database object
use
fun countUsers() = openDatabase().use { it.count("users") }
use
with
/**
* Calls the specified function [block] with the given [receiver]
* as its receiver and returns its result.
*/
public inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block()
with
recyclerView.setHasFixedSize(true)
recyclerView.addItemDecoration(createDecorator())
recyclerView.layoutManager = LinearLayoutManager(applicationContext)
recyclerView.adapter = myAdapter
with
with(recyclerView) {
recyclerView.setHasFixedSize(true)
recyclerView.addItemDecoration(createDecorator())
recyclerView.layoutManager = LinearLayoutManager(applicationContext)
recyclerView.adapter = myAdapter
}
with
with(recyclerView) {
recyclerView.setHasFixedSize(true)
recyclerView.addItemDecoration(createDecorator())
recyclerView.layoutManager = LinearLayoutManager(applicationContext)
recyclerView.adapter = myAdapter
}
Not need
with
with(recyclerView) {
setHasFixedSize(true)
addItemDecoration(createDecorator())
layoutManager = LinearLayoutManager(applicationContext)
adapter = myAdapter
}
with
with(recyclerView) {
setHasFixedSize(true)
addItemDecoration(createDecorator())
layoutManager = LinearLayoutManager(applicationContext)
adapter = myAdapter
}
apply
/**
* Calls the specified function [block] with `this` value as its receiver
* and returns `this` value.
*/
public inline fun <T> T.apply(block: T.() -> Unit): T { block(); return this }
apply
fun makeDir(path: String): File {
val result: File = File(path)
result.mkdirs()
return result
}
apply
fun makeDir(path: String) = File(path).apply { mkdirs() }
Collections
Collections
val numbers: MutableList<Int> = mutableListOf(1, 2, 3)
numbers.add(1)
val numbers2: List<Int> = listOf(1, 2, 3)
numbers2.add(1)
No such method
Collections
mutableListOf(1, null, 2, null, 3, 4, 5, 6, 7, 8, 9)
.filterNotNull()
.filter { it % 2 == 0 }
.sortedDescending()
> [1, null, 2, null, 3, 4, 5, 6, 7, 8, 9]
Collections
mutableListOf(1, null, 2, null, 3, 4, 5, 6, 7, 8, 9)
.filterNotNull()
.filter { it % 2 == 0 }
.sortedDescending()
> [1, 2, 3, 4, 5, 6, 7, 8, 9]
Collections
mutableListOf(1, null, 2, null, 3, 4, 5, 6, 7, 8, 9)
.filterNotNull()
.filter { it % 2 == 0 }
.sortedDescending()
> [2, 4, 6, 8]
Collections
mutableListOf(1, null, 2, null, 3, 4, 5, 6, 7, 8, 9)
.filterNotNull()
.filter { it % 2 == 0 }
.sortedDescending()
> [8, 6, 4, 2]
Collections
getOrElse()
find()
filter()
filterNot()
filterNotNull()
flatMap()
take()
takeLast()
sortBy()
sortByDescending()
groupBy()
map()
mapNotNull()
all()
any()
maxBy()
minBy()
minWith()
sumBy()
zip()
...
Functions default values
Default values for function parameters
• Function parameters can have default values, which are used when a
corresponding argument is omitted.
• This allows for a reduced number of overloads compared to other
languages.
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String?,
selectionArgs : Array<String>?,
orderBy: String?): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), null, null, "NAME")
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String? = null,
selectionArgs : Array<String>? = null,
orderBy: String? = null): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), null, null, "NAME")
Default value
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String? = null,
selectionArgs : Array<String>? = null,
orderBy: String? = null): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), null, null, "NAME")
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String? = null,
selectionArgs : Array<String>? = null,
orderBy: String? = null): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), null, null, orderBy = "NAME")
Named argument
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String? = null,
selectionArgs : Array<String>? = null,
orderBy: String? = null): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), null, null, orderBy = "NAME")
Not needed
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String? = null,
selectionArgs : Array<String>? = null,
orderBy: String? = null): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), orderBy = "NAME")
Lazy property
Lazy property
• Value gets computed only upon first access.
Lazy property
val preference = getSharedPreferences("pref")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val username = preference.getString("username")
}
Lazy property
val preference = getSharedPreferences("pref")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val username = preference.getString("username")
}
Crash, require context
Lazy property
val preference by lazy { getSharedPreferences("pref") }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val username = preference.getString("username")
}
Won’t be executed until the
property is first used
Lazy property
val preference by lazy { getSharedPreferences("pref") }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val username = preference.getString("username")
}
Extension functions
Extension functions
public fun isLollipopOrGreater(code: Int): Boolean {
return code >= Build.VERSION_CODES.LOLLIPOP
}
Extension functions
public fun isLollipopOrGreater(code: Int): Boolean {
return code >= Build.VERSION_CODES.LOLLIPOP
}
Extension functions
public fun Int.isLollipopOrGreater(code: Int): Boolean {
return code >= Build.VERSION_CODES.LOLLIPOP
}
Extension functions
public fun Int.isLollipopOrGreater(): Boolean {
return code >= Build.VERSION_CODES.LOLLIPOP
}
Extension functions
public fun Int.isLollipopOrGreater(): Boolean {
return this >= Build.VERSION_CODES.LOLLIPOP
}
Extension functions
public fun Int.isLollipopOrGreater(): Boolean {.
return this >= Build.VERSION_CODES.LOLLIPOP
}
if (Build.VERSION.SDK_INT.isLollipopOrGreater) {
// ...
}
Extension functions
public fun Int.isLollipopOrGreater(): Boolean {.
return this >= Build.VERSION_CODES.LOLLIPOP
}
if (16.isLollipopOrGreater) {
// ...
}
Extension functions
Function<Customer, Order> customerMapper = // ...
Function<Order, Boolean> orderFilter = // ...
Function<Order, Float> orderSorter = // ...
List<Order> vipOrders = sortBy(filter(map(customers,
customerMapper),
orderFilter),
orderSorter);
Extension functions
Function<Customer, Order> customerMapper = // ...
Function<Order, Boolean> orderFilter = // ...
Function<Order, Float> orderSorter = // ...
List<Order> vipOrders = sortBy(filter(map(customers,
customerMapper),
orderFilter),
orderSorter);
Extension functions
Function<Customer, Order> customerMapper = // ...
Function<Order, Boolean> orderFilter = // ...
Function<Order, Float> orderSorter = // ...
List<Order> vipOrders = sortBy(filter(map(customers,
customerMapper,
orderFilter),
orderSorter);
Extension functions
Function<Customer, Order> customerMapper = // ...
Function<Order, Boolean> orderFilter = // ...
Function<Order, Float> orderSorter = // ...
List<Order> vipOrders = sortBy(filter(map(customers,
customerMapper),
orderFilter),
orderSorter);
Extension functions
Function<Customer, Order> customerMapper = // ...
Function<Order, Boolean> orderFilter = // ...
Function<Order, Float> orderSorter = // ...
List<Order> vipOrders = sortBy(filter(map(customers,
customerMapper),
orderFilter),
orderSorter);
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Primary constructors
Primary constructors
class Customer {
var firstName: String = // ...
var lastName: String = // ...
var email: String = // ...
}
Primary constructors
class Customer(firstName: String, lastName: String, email: String) {
var firstName: String = // ...
var lastName: String = // ...
var email: String = // ...
}
Primary constructors
class Customer(firstName: String, lastName: String, email: String) {
var firstName: String = firstName
var lastName: String = lastName
var email: String = email
}
Primary constructors
class Customer(firstName: String, lastName: String, email: String) {
var firstName: String
var lastName: String
var email: String
init {
this.firstName = firstName
this.lastName = lastName
this.email = email
}
}
Primary constructors
class Customer(firstName: String, lastName: String, email: String)
Primary constructors
class Customer(var firstName: String, var lastName: String, var email: String)
Primary constructors
class Customer(
var firstName: String,
var lastName: String,
var email: String)
Primary constructors
class Customer(
val firstName: String,
val lastName: String,
val email: String)
Properties
Properties
class Customer {
private String firstName;
private String lastName;
private String email;
public String getFirstName() { return firstName;}
public String getLastName() { return lastName; }
public String getEmail() { return email; }
public void setFirstName(String firstName) { this.firstName = firstName }
public void setLastName(String lastName) { this.lastName = lastName }
public void setEmail(String email) { this.email = email }
}
Properties
class Customer {
private String firstName;
private String lastName;
private String email;
public String getFirstName() { return firstName;}
public String getLastName() { return lastName; }
public String getEmail() { return email; }
public void setFirstName(String firstName) { this.firstName = firstName }
public void setLastName(String lastName) { this.lastName = lastName }
public void setEmail(String email) { this.email = email }
}
Properties
class Customer {
private String firstName;
private String lastName;
private String email;
public String getFirstName() { return firstName;}
public String getLastName() { return lastName; }
public String getEmail() { return email; }
public void setFirstName(String firstName) { this.firstName = firstName }
public void setLastName(String lastName) { this.lastName = lastName }
public void setEmail(String email) { this.email = email }
}
Properties
class Customer {
private String firstName;
private String lastName;
private String email;
public String getFirstName() { return firstName;}
public String getLastName() { return lastName; }
public String getEmail() { return email; }
public void setFirstName(String firstName) { this.firstName = firstName }
public void setLastName(String lastName) { this.lastName = lastName }
public void setEmail(String email) { this.email = email }
}
Properties
class Customer {
var firstName: String = // ...
var lastName: String = // ...
var email: String = // ...
}
Properties
class Customer {
var firstName: String = // ...
var lastName: String = // ...
var email: String = // ...
}
val customer = Customer()
customer.firstName = "Michael"
customer.lastName = "Pardo"
customer.email = "michael@michaelpardo.com"
Data class
Data class
What it does?
Nothing, just hold data
What it provides?
● getters, setters
● equals()/hashCode()
● toString() ofthe form"User(name=John, age=42)"
● copy() function
Data class
data class User(val name: String, val age: Int)
Data class
data class User(val name: String, val age: Int)
val user = User("Dmytro", 24)
print(user)
> User(name=Dmytro, age=24)
Singletons
Singletons
public class Singleton {
private static volatile Singleton instance;
private Singleton() { }
public static Singleton getInstance() {
if (instance == null ) {
synchronized (Singleton.class) {
if (instance == null) {
instance = new Singleton();
}
}
}
return instance;
}
}
Singletons
public class Singleton {
private static volatile Singleton instance = null;
private Singleton() { }
public static synchronized Singleton getInstance() {
if (instance == null) {
instance = new Singleton();
}
return instance;
}
}
Singletons
public class Singleton {
private static final Singleton INSTANCE = new Singleton();
private Singleton() {}
public static Singleton getInstance() {
return INSTANCE;
}
}
Singletons
public class Singleton {
private static final Singleton instance;
static {
try {
instance = new Singleton();
} catch (Exception e) {
throw new RuntimeException("an error occurred!", e);
}
}
public static Singleton getInstance() {
return instance;
}
private Singleton() { }
}
Singletons
public class Singleton {
private Singleton() { }
private static class SingletonHolder {
private static final Singleton INSTANCE = new Singleton();
}
public static Singleton getInstance() {
return SingletonHolder.INSTANCE;
}
}
Singletons
object Singleton
Singletons
object Logger {
val tag = "TAG"
fun d(message: String) {
Log.d(tag, message)
}
}
Companion objects
Companion objects
class LaunchActivity extends AppCompatActivity {
public static final String TAG = LaunchActivity.class.getName();
public static void start(Context context) {
context.startActivity(new Intent(context, LaunchActivity.class));
}
}
Companion objects
class LaunchActivity extends AppCompatActivity {
public static final String TAG = LaunchActivity.class.getName();
public static void start(Context context) {
context.startActivity(new Intent(context, LaunchActivity.class));
}
}
Companion objects
class LaunchActivity extends AppCompatActivity {
public static final String TAG = LaunchActivity.class.getName();
public static void start(Context context) {
context.startActivity(new Intent(context, LaunchActivity.class));
}
}
Companion objects
class LaunchActivity extends AppCompatActivity {
public static final String TAG = LaunchActivity.class.getName();
public static void start(Context context) {
context.startActivity(new Intent(context, LaunchActivity.class));
}
}
Timber.v("Starting activity %s", LaunchActivity.TAG);
Companion objects
class LaunchActivity extends AppCompatActivity {
public static final String TAG = LaunchActivity.class.getName();
public static void start(Context context) {
context.startActivity(new Intent(context, LaunchActivity.class));
}
}
Timber.v("Starting activity %s", LaunchActivity.TAG);
LaunchActivity.start(context);
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Timber.v("Starting activity ${LaunchActivity.TAG}")
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Timber.v("Starting activity ${LaunchActivity.TAG}")
LaunchActivity.start(context)
Operator overloading

More Related Content

What's hot

02 arrays
02 arrays02 arrays
02 arrays
Rajan Gautam
 
Python list
Python listPython list
Structured data type
Structured data typeStructured data type
Structured data type
Omkar Majukar
 
Functional programming from its fundamentals
Functional programming from its fundamentalsFunctional programming from its fundamentals
Functional programming from its fundamentals
Mauro Palsgraaf
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
Intro C# Book
 
Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search Techniques
Shakil Ahmed
 
Intro To Erlang
Intro To ErlangIntro To Erlang
Intro To Erlang
asceth
 
Numerical analysisgroup19
Numerical analysisgroup19Numerical analysisgroup19
Numerical analysisgroup19
UltraviolenceKOBAIVA
 
The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184
Mahmoud Samir Fayed
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning Programmers
Kimikazu Kato
 
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
Philip Schwarz
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
Corrado Santoro
 
Channel coding
Channel codingChannel coding
Channel coding
Piyush Mittal
 
Kotlin standard
Kotlin standardKotlin standard
Kotlin standard
Myeongin Woo
 

What's hot (14)

02 arrays
02 arrays02 arrays
02 arrays
 
Python list
Python listPython list
Python list
 
Structured data type
Structured data typeStructured data type
Structured data type
 
Functional programming from its fundamentals
Functional programming from its fundamentalsFunctional programming from its fundamentals
Functional programming from its fundamentals
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
 
Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search Techniques
 
Intro To Erlang
Intro To ErlangIntro To Erlang
Intro To Erlang
 
Numerical analysisgroup19
Numerical analysisgroup19Numerical analysisgroup19
Numerical analysisgroup19
 
The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning Programmers
 
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
Channel coding
Channel codingChannel coding
Channel coding
 
Kotlin standard
Kotlin standardKotlin standard
Kotlin standard
 

Similar to Kotlin for Android Developers - 2

Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
kesav24
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
진성 오
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
vsssuresh
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
intelliyole
 
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202
Mahmoud Samir Fayed
 
Poly-paradigm Java
Poly-paradigm JavaPoly-paradigm Java
Poly-paradigm Java
Pavel Tcholakov
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
Mario Fusco
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Aleksandar Prokopec
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
sowmya koneru
 
Python
PythonPython
C programs
C programsC programs
Monadologie
MonadologieMonadologie
Monadologie
league
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
Ramachendran Logarajah
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and tests
intive
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210
Mahmoud Samir Fayed
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Philip Schwarz
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Codemotion
 

Similar to Kotlin for Android Developers - 2 (20)

Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202
 
Poly-paradigm Java
Poly-paradigm JavaPoly-paradigm Java
Poly-paradigm Java
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
 
Python
PythonPython
Python
 
C programs
C programsC programs
C programs
 
Monadologie
MonadologieMonadologie
Monadologie
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and tests
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 

Recently uploaded

Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 

Recently uploaded (20)

Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 

Kotlin for Android Developers - 2