
- Android Basics
- Android - Home
- Android - Overview
- Android - Environment Setup
- Android - Architecture
- Android - Application Components
- Android - Hello World Example
- Android - Resources
- Android - Activities
- Android - Services
- Android - Broadcast Receivers
- Android - Content Providers
- Android - Fragments
- Android - Intents/Filters
- Android - User Interface
- Android - UI Layouts
- Android - UI Controls
- Android - Event Handling
- Android - Styles and Themes
- Android - Custom Components
- Android Advanced Concepts
- Android - Drag and Drop
- Android - Notifications
- Location Based Services
- Android - Sending Email
- Android - Sending SMS
- Android - Phone Calls
- Publishing Android Application
- Android Useful Examples
- Android - Alert Dialoges
- Android - Animations
- Android - Audio Capture
- Android - AudioManager
- Android - Auto Complete
- Android - Best Practices
- Android - Bluetooth
- Android - Camera
- Android - Clipboard
- Android - Custom Fonts
- Android - Data Backup
- Android - Developer Tools
- Android - Emulator
- Android - Facebook Integration
- Android - Gestures
- Android - Google Maps
- Android - Image Effects
- Android - ImageSwitcher
- Android - Internal Storage
- Android - JetPlayer
- Android - JSON Parser
- Android - Linkedin Integration
- Android - Loading Spinner
- Android - Localization
- Android - Login Screen
- Android - MediaPlayer
- Android - Multitouch
- Android - Navigation
- Android - Network Connection
- Android - NFC Guide
- Android - PHP/MySQL
- Android - Progress Circle
- Android - ProgressBar
- Android - Push Notification
- Android - RenderScript
- Android - RSS Reader
- Android - Screen Cast
- Android - SDK Manager
- Android - Sensors
- Android - Session Management
- Android - Shared Preferences
- Android - SIP Protocol
- Android - Spelling Checker
- Android - SQLite Database
- Android - Support Library
- Android - Testing
- Android - Text to Speech
- Android - TextureView
- Android - Twitter Integration
- Android - UI Design
- Android - UI Patterns
- Android - UI Testing
- Android - WebView Layout
- Android - Wi-Fi
- Android - Widgets
- Android - XML Parsers
- Android Useful Resources
- Android - Questions and Answers
- Android - Useful Resources
- Android - Discussion
What is the Kotlin double-bang (!!) operator?
In Kotlin, "!!" is an operator that is known as the double-bang operator. This operator is also known as "not-null assertion operator". This operator is used to convert any value to a non-NULL type value and it throws an exception if the corresponding value is NULL. In the following example, we will see how to use this double-bang operator.
Example 1
In this example, we will consider a variable "name" and as a programmer, we want to throw a NULL pointer exception whenever the value of "name" is NULL. Now, execute the following code
fun main(args: Array<String>) { var name: String? name = null println(name) }
Output
It will generate the following output −
null
This code is not actually solving our requirement statement. We wanted to throw a NULL pointer exception whenever the value of "name" is NULL. Let’s modify our previous example with the help of double-bang operator (!!).
Example 2
fun main(args: Array<String>) { var name: String? name = null // Nothing has been used to resolve overload ambiguity exception println(name!! is Nothing?) }
Output
It will throw a NULL Pointer Exception at runtime −
Exception in thread "main" java.lang.NullPointerException at MainKt.main(main.kt:6)
- Related Articles
- What is the "double tilde" (~~) operator in JavaScript?
- What is double address operator(&&) in C++?
- What does the "===" operator do in Kotlin?
- What is the syntax for leading bang! in JavaScript function?
- What does the Double Star operator mean in Python?
- What does "?:" do in Kotlin? (Elvis Operator)
- What does double question mark (??) operator mean in PHP ?
- Double not (!!) operator in PHP
- Apply Ternary operator on double value in Java
- What is Double DES?
- What is the ?-->? operator in C++?
- What is the operator in MySQL?
- What is Double Extortion Ransomware?
- What is the conditional operator ?: in Java?
- What is Python equivalent of the ! operator?
