Android Development with Kotlin by Marcin Moskala
Author:Marcin Moskala
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2017-09-25T12:16:26+00:00
// Tester1.kt
fun main(args: Array<String>) { a() }
// Tester2.kt
inline fun a() { b() }
private fun b() { print("B") }
How is it possible? For the internal modifier it is simpler, because the internal modifier is public under the hood. For private functions, there is an additional access$b function created that has public visibility and that is only invoking the b function:
public static final void access$b() { b(); }
This behavior is presented here just to explain why less restrictive modifiers can sometimes be used inside inline functions (these situations can be found in Kotlin standard library in Kotlin 1.1). In the projects, we should design elements in such a way that there is no need to use such suppressions.
Another problem is less intuitive. While no lambda has been created, we cannot pass parameters that are of the function type to another function. Here is an example:
fun boo(f: ()->Int) { //... } inline fun foo(f: () -> Int) { boo (f) // ERROR, 1 }
When function is inline, then its function arguments cannot be passed to function that are not inline.
This doesn't work because no f parameter has been created. It has just been defined to be replaced by the function literal body. This is why it cannot be passed to another function as an argument.
The simplest way to deal with it is by making the boo function inline as well. Then it will be OK. In most cases, we cannot make too many functions inline. Here are a few reasons why:
The inline functions should be used for smaller functions. If we are making inline functions that are using other inline functions, then it can lead to a large structure being generated after compilation. This is a problem both because of compilation time and because of the resulting code's size.
While inline functions cannot use element with visibility modifiers more strict than the one they have, it would be a problem if we would like to use them in libraries where as many functions as possible should be private to protect the API.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6532)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6409)
Kotlin in Action by Dmitry Jemerov(5062)
Odoo 15 Development Essentials - Fifth Edition by Daniel Reis & Greg Mader(3337)
Odoo 15 Development Essentials by Daniel Reis(2814)
React Native - Building Mobile Apps with JavaScript by Novick Vladimir(2529)
Learning Angular - Second Edition by Christoffer Noring(2358)
Pride and Prejudice by Jane Austen(2349)
Mobile Forensics Cookbook by Igor Mikhaylov(2017)
Computers For Seniors For Dummies by Nancy C. Muir(1995)
Bulletproof Android: Practical Advice for Building Secure Apps (Developer's Library) by Godfrey Nolan(1872)
Android Development with Kotlin by Marcin Moskala & Igor Wojda(1797)
Building Android UIs with Custom Views by Raimon Ràfols Montané(1789)
1936941139 (N) by Bob Rosenthal(1731)
Building Progressive Web Apps: Bringing the Power of Native to the Browser by Ater Tal(1725)
Hands-On Internet of Things with MQTT by Tim Pulver(1706)
Android App Development by Franceschi Hervé J.;(1702)
Ember.js in Action by Joachim Haagen Skeie(1689)
Hands-On Design Patterns with React Native by Mateusz Grzesiukiewicz(1655)
