
- 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
How does the reified keyword work in Kotlin?
"reified" is a special type of keyword that helps Kotlin developers to access the information related to a class at runtime. "reified" can only be used with inline functions. When "reified" keyword is used, the compiler copies the function’s bytecode to every section of the code where the function has been called. In this way, the generic type T will be assigned to the type of the value it gets as an argument.
Example
In this example, we will see how "reified" is helpful to re-use our code and use the same function to perform similar kind of operation regardless of its passing argument.
For this example, we have created an Inline function and we are passing a generic "reified" argument T and from the main() of Kotlin, we are calling myExample() multiple times with different arguments.
// Declaring Inline function inline fun <reified T> myExample(name: T) { println("
Name of your website -> "+name) println("
Type of myClass: ${T::class.java}") } fun main() { // calling func() with String myExample<String>("www.tutorialspoint.com") // calling func() with Int value myExample<Int>(100) // calling func() with Long value myExample<Long>(1L) }
Output
It will generate the following output −
Name of your website -> www.tutorialspoint.com Type of myClass: class java.lang.String Name of your website -> 100 Type of myClass: class java.lang.Integer Name of your website -> 1 Type of myClass: class java.lang.Long
- Related Articles
- How does the “this” keyword work in JavaScript?
- What does 'by' keyword do in Kotlin?
- How to work with this keyword in Java?
- What is "out" keyword in Kotlin?
- How to work with Maps in Kotlin?
- How does the magnets work?
- How does the array_diff_key() work in PHP?
- How does the Microstrip antenna work?
- How does the Selenium WebDriver work?
- How does the discordancy testing work?
- How does the WannaCry malware work?
- How does the Docker network work?
- How does jQuery.scrollTop() work?
- How does jQuery.scrollLeft() work?
- How does classification work?
