Закрыть
×
=0) { let js = text.slice(pos1, pos2); + '<\/' + "script" + '>'; arrText.push(js); // next pos1 = pos2; continue; } } } break; } return arrText; } function OpenDialog(parentDiv, urlContent) { parentDiv = document.getElementById('modal-background'); // new !!!!!!! parentDiv.appendChild(document.getElementById('modal-template')); document.getElementById('modal-background').style.display = "flex"; // !!!!! block document.getElementById('modal-template').style.display = "flex"; // !!!!! document.getElementById('modal-body').innerHTML = ""; post_url(urlContent, "", function(text_from_server) { var element = document.getElementById('modal-body'); element.innerHTML = text_from_server; // add scripts var arrJSText = get_scripts(text_from_server); for (var i=0; i
dir.by
Праздники ...
Праздники ...
Рождество (Католическое) 25 Декабря
Концерты, выставки ...
Концерты, выставки ...
Спектакль "Укрощение мужчин"|||г. Минск 12 сентября, 3 октября, 1 ноября, 27 декабря 2026
Афишу
Спорт занятия ...
Спорт занятия ...
Занятия в тренажерном зале
Спорт занятие
Компьютер, программы...
Компьютер, программы...
Объявления ...
Объявления ...
Комбинезон рост 110 PLAY TODEY
Объявление
Новости ...
Новости ...
Форум ...
Форум ...
обсуждение...
<<
Поиск >>
Поиск
Концерты
Спорт
Форум
Компьютер
Компьютер, программы
→
Kotlin
null value, use the symbol ? and ?. and !! and ?: and !!. and ?. in Kotlin
посмотрели
3333
раз
обновлено: 15 September 2026
? null
To specify an empty value in a variable
Add the
?
character to the type and assign the empty value
null
Kotlin
var
bookPrice:Int
?
=
null
!!  
Take a value from a variable with an exception
Add
!!
to take the value.
If we use
!!
and the value is
null
, then a
exception
is thrown.
Kotlin
var
bookPrice1:Int
?
= 10
var
bookPrice2:Int
?
=
null
var
bookPrice3:Int
?
= 7
var
allPrice:
Int
= bookPrice1
!!
+ bookPrice2
!!
+ bookPrice3
!!
Note!
In my example,
allPrice
is not calculated because
bookPrice2
!!
will throw an exception.
!!.
Call a class method with an exception
Add
!!.
to call the method.
If we use
!!.
and the value is
null
, then a
exception
is thrown.
Kotlin
class
MyBook
{
fun
Show
()
{
println(
"Hello"
)
}
}
fun
main
() {
var
b1:MyBook
?
=
null
b1
!!.
Show()
}
In my example, the
Show
method won't be called because
b1
!!.
will throw an exception.
Safe Call Operator
?.
Call class method without exception, get null without exception
Kotlin
class
MyBook
{
val
Name:
String
=
"Hello"
fun
Show
()
{
println(
"Hello"
)
}
}
fun
main
() {
var
b1:MyBook
?
=
null
val
myLength = b1
?.
Name
?.
length
// myLength = null
// There will be no exception
b1
?.
Show()
// method will not be called. There will be no exception
}
Elvis Cinematographer
?:
Take a value from a variable without exception
Add
?:
to take the value.
If we use
?:
and the value is
null
, then we set the value ourselves.
Kotlin
var
bookPrice1:Int
?
= 10
var
bookPrice2:Int
?
=
null
var
bookPrice3:Int
?
= 7
var
allPrice:
Int
= (bookPrice1
?:
0) + (bookPrice2
?:
0) + (bookPrice3
?:
0)
// allPrice = 17
Kotlin
val
nameLength:
Int
= name?.length ?: 1
// name = null
// nameLength = 1
← Previous topic
Declare the variable and set the value in Kotlin | val, var, lateinit, constant: const val, global variable: companion object
Next topic →
Integer numbers in Kotlin are: Byte, UByte, Short, UShort, Int, UInt, Long, ULong
Your feedback ... Comments ...
Your Name
Your comment
(www links can only be added by a logged-in user)
+ Picture
Новость
"Черная пятница" Dreame в Беларуси – две недели скидок до 3400 рублей
•
What is Kotlin?
•
Why is IntelliJ IDEA the most popular development environment for Kotlin?
•
Download and install IntelliJ IDEA to explore Kotlin
•
Create a new console project to explore Kotlin | IntelliJ IDEA
Setting the value
•
Declare the variable and set the value in Kotlin | val, var, lateinit, constant: const val, global variable: companion object
null
•
null value, use the symbol ? and ?. and !! and ?: and !!. and ?. in Kotlin
Int, Float, Boolean, Char ...
•
Integer numbers in Kotlin are: Byte, UByte, Short, UShort, Int, UInt, Long, ULong
•
Decimal numbers in Kotlin are: Float, Double
•
A flag with values of true or false in Kotlin is: Boolean
•
The symbol in Kotlin is: Char
•
Convert number to text in Kotlin | Int → String
String
•
The string, the text in Kotlin is: String
•
Interpolate strings in Kotlin. Example: val address:String = "${street}, ${country}"
•
What is the difference between String and StringBuilder ?
Enum
•
What is an enumeration (enum) in Kotlin ?
•
How do I find enum by value in Kotlin ?
Collections and Arrays
•
Collections in Kotlin
•
Lists in Kotlin: interface List , interface MutableList , class ArrayList. Functions to create: listOf(...), mutableListOf(...), arrayListOf(...)
•
Arrays in Kotlin: class Array<T>, class IntArray, class FloatArray. Functions to create: arrayOf(...), intArrayOf(...), floatArrayOf(...)
Function
•
fun() { ... } is a function in Kotlin. The function is needed to perform an action.
Extension function
•
Extension function in Kotlin. Allows you to add a new function to the system (List, ..) or my (Book, ...) class
Lambda function
•
Lambda function in Kotlin. Example 1: var myFunc1 : (a:Int, b:Int) -> Int = { p1, p2 -> p1 + p2 };
Class
•
What is class in Kotlin? Example: class MyBook { ... } | Primary and secondary constructor | block init
•
Access modifiers (private, protected, public) for a class and for methods and fields. | Kotlin
•
lateinit is a late initialization for the class field | Kotlin
•
class that inherits from interface in Kotlin | Example: class MyBook : IBook { ...}
•
Unnamed class that inherits from interface in Kotlin | Example: val book1 = object : IBook { ...}
•
Generic, template class in Kotlin | Example: class MyBook<T> { ... }
Flow
•
flow is the data flow in Kotlin. These are the substitution of LiveData in Android Kotlin and the substitution of Observable in RxJava
Writing a program
•
The Kotlin console app works like Android Jetpack Compose
Ваши вопросы присылайте по почте:
info@dir.by