![]() This is a really clever way for Kotlin to workaround the JVM issue by maneuvering the underlying bytecode! Really, Kotlin is just a language that is a bunch of workarounds for annoyances in the JVM.For example, if we create a Set and put a few strings into it, at runtime we’re only able to see it as a Set. The inline keyword is what is responsible for telling the compiler to replace every call to the function with the actual code implementation the function in the bytecode. Is certainly an upgrade from this - crewCrewCrew.forEach printAllAnimalResults(Mammal::knownSpeciesCount) Don’t worry, you will start seeing it after looking at a couple more examples. Sure, there’s a lot going on in this function. In our case, we expect to return a List of the Mammal type or the subtype of Mammal. Type parameter used in the return type: We expect to return a List of type T, or whatever we end up passing in as T.Whatever we pass in as T is designated by the type parameter declaration, if there is one. Type parameter used in the receiver type: This function is an extension function for a List of type T. ![]() ![]() This is what bounded type parameters are for. For example, this method only wants to accept instances of Mammal or its subtypes. There may be times when you want to restrict the types that can be used as type arguments in a parameterized type. Type parameter declaration: In order to use a generic method as an ordinary method, you must specify a type between angle brackets. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |