is
!is
- is
!is
:
if (obj is String) {
print(obj.length)
}
if (obj !is String) { // !(obj is String)
print("Not a String")
}
else {
print(obj.length)
}
, Kotlin , is
-
, .
fun demo(x: Any) {
if (x is String) {
print(x.length) // x String
}
}
, , (!is
)
:
if (x !is String) return
print(x.length) // x String
, &&
||
:
// x String `||`
if (x !is String || x.length == 0) return
// x is String `&&`
if (x is String && x.length > 0) {
print(x.length) // x String
}
when (x) {
is Int -> print(x + 1)
is String -> print(x.length + 1)
is IntArray -> print(x.sum())
}
, , . , :
private
internal
, , .
, , getter';, . , . Kotlin as:
val x: String = y as String
, null String
, String
nullable,
.. y
- null, . Java, nullable :
val x: String? = y as String?
, as?, null :
val x: String? = y as? String
, , as? non-null String
, nullable.
is
!is
- is
!is
:
if (obj is String) {
print(obj.length)
}
if (obj !is String) { // !(obj is String)
print("Not a String")
}
else {
print(obj.length)
}
, Kotlin , is
-
, .
fun demo(x: Any) {
if (x is String) {
print(x.length) // x String
}
}
, , (!is
)
:
if (x !is String) return
print(x.length) // x String
, &&
||
:
// x String `||`
if (x !is String || x.length == 0) return
// x is String `&&`
if (x is String && x.length > 0) {
print(x.length) // x String
}
when (x) {
is Int -> print(x + 1)
is String -> print(x.length + 1)
is IntArray -> print(x.sum())
}
, , . , :
private
internal
, , .
, , getter';, . , . Kotlin as:
val x: String = y as String
, null String
, String
nullable,
.. y
- null, . Java, nullable :
val x: String? = y as String?
, as?, null :
val x: String? = y as? String
, , as? non-null String
, nullable.
10.11.2021 - 12:37: - Personalias -> WHO IS WHO - - _. 10.11.2021 - 12:36: - Conscience -> . ? - _. 10.11.2021 - 12:36: , , - Upbringing, Inlightening, Education -> ... - _. 10.11.2021 - 12:35: - Ecology -> - _. 10.11.2021 - 12:34: , - War, Politics and Science -> - _. 10.11.2021 - 12:34: , - War, Politics and Science -> . - _. 10.11.2021 - 12:34: , , - Upbringing, Inlightening, Education -> , - _. 10.11.2021 - 09:18: - New Technologies -> , 5G- - _. 10.11.2021 - 09:18: - Ecology -> - _. 10.11.2021 - 09:16: - Ecology -> - _. 10.11.2021 - 09:15: , , - Upbringing, Inlightening, Education -> - _. 10.11.2021 - 09:13: , , - Upbringing, Inlightening, Education -> - _. |