Android Development with Kotlin by Marcin Moskala & Igor Wojda
Author:Marcin Moskala & Igor Wojda [Moskala, Marcin]
Language: eng
Format: azw3, epub
Publisher: Packt Publishing
Published: 2017-08-30T04:00:00+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
Android Development with Kotlin by Marcin Moskala & Igor Wojda.epub
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.
Hello! Python by Anthony Briggs(9365)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9336)
The Mikado Method by Ola Ellnestam Daniel Brolund(9300)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7845)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7397)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7306)
Grails in Action by Glen Smith Peter Ledbrook(7291)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7111)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5951)
Kotlin in Action by Dmitry Jemerov(4633)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(3848)
Functional Programming in JavaScript by Mantyla Dan(3719)
Learning Java by Patrick Niemeyer & Daniel Leuck(2867)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2831)
Mastering Python for Finance by Weiming James Ma;(2825)
WordPress Plugin Development Cookbook by Yannick Lefebvre(2578)
Mastering Java 9 by Dr. Edward Lavieri(2569)
Architecting Modern Java EE Applications: Designing lightweight, business-oriented enterprise applications in the age of cloud, containers, and Java EE 8 by Daschner Sebastian(2555)
Learning Concurrency in Python by Elliot Forbes(2547)