extension-function Questions
10
Solved
I want to make a extension function in Kotlin, that converts the first letter of each word of the string to upper case
the quick brown fox
to
The Quick Brown Fox
I tried using the capitalize(...
Lacework asked 27/8, 2018 at 15:51
3
I Kotlin if I have an interface like this:
interface User {
val name: String
val email: String
}
I can write an extension function like this anywhere in the code:
fun User.toUserDto(): UserDto {...
Tolbert asked 9/2, 2021 at 20:8
3
Solved
If we want to test an extension function on a type, we can create an instance of this type, call the function and check the returned value. But what about testing extension functions defined inside...
Congreve asked 5/6, 2018 at 14:21
2
Solved
In Kotlin language, what does this syntax do and how does it work ?
class ClassName1 {
companion object {
fun ClassName2.funName()=""
}
}
Caraway asked 7/6, 2022 at 14:22
4
Solved
I want my extension function to have a couple of receivers. For example, I want function handle to be able to call methods of both CoroutineScope and Iterable instances:
fun handle() {
// I want t...
Holusbolus asked 17/1, 2022 at 9:57
2
Solved
Kotlin version 1.2.50
I have been following some examples on this tutorial on youtube https://www.youtube.com/watch?v=gPH9XnvpoXE. And there are a few things that I have understood, but there is st...
Footworn asked 7/10, 2018 at 12:31
2
How can I call a super's extension function?
For example:
open class Parent {
open fun String.print() = println(this)
}
class Child : Parent() {
override fun String.print() {
print("child say...
Aemia asked 2/6, 2017 at 3:51
9
Solved
Is it possible to access extension functions from Java code?
I defined the extension function in a Kotlin file.
package com.test.extensions
import com.test.model.MyModel
/**
*
*/
public fun M...
Elroyels asked 3/2, 2015 at 8:37
2
I see some usages of Extension functions in Kotlin I don't personally think that makes sense, but it seems that there are some guidelines that "apparently" support it (a matter of interpr...
Aloisia asked 10/2, 2021 at 13:3
2
Solved
In Java you cannot extend a final class, but in Kotlin you can write extension method to such final classes. How did they make it work internally? I couldn't find any article that explained the inn...
Buroker asked 6/8, 2020 at 14:34
4
Solved
I am very new to Kotlin.
I want to be able to add a function to my abstract class, so when I define that function I will be able to invoke that on every child from that class(they inherit the abst...
Dramatic asked 2/10, 2017 at 10:42
1
Solved
I have a pretty short question about an extension function that would help clear some of my code. Basically I have some transformations on the hashCode of a class name and I want an extension funct...
Gilletta asked 10/10, 2019 at 7:31
2
I was reading about Kotlin and did not quite get the idea.
From what I understood, an extension function adds behavior to instances of a class T without having to inherit from T.
and what is receiv...
Respiration asked 1/9, 2017 at 11:25
4
Solved
Suppose I have the following code that I want to make as a re-usable component:
fun <T> MutableList<T>.swap(index1: Int, index2: Int) {
val tmp = this[index1] // 'this' corresponds to...
Sextodecimo asked 20/2, 2019 at 10:51
1
Solved
We are currently switching our project to Kotlin, and ran across following question:
We need a certain extension function only inside a given class. Thus, we have two possibilities: (1) Declaring ...
Jesicajeske asked 20/2, 2019 at 9:22
2
Solved
I read many Kotlin documents about these items. But I can't understand so clearly.
What is the use of Kotlin let, also, takeIf and takeUnless in detail?
I need an example of each item. Please don...
Worldlywise asked 9/8, 2017 at 6:3
1
Solved
The only way I've found so far is to create an instance of the given class and then using the autocomplete to see all possible functions. Obviously, this way is cumbersome and takes too much time. ...
Polyphony asked 21/9, 2017 at 6:23
4
Solved
I want to create extension functions for classes that encapsulate simple Numbers. For example DoubleProperty. I encountered the problem, that I can't overload the + and the += operator at the same ...
Forman asked 15/6, 2017 at 4:38
1
Solved
Hey I want to make a class in kotlin that will hold all extension functions that I will use in a few places for example:
class DateUtils {
//in this case I use jodatime
fun Long.toDateTime() : D...
Idioblast asked 3/6, 2017 at 18:57
2
Solved
Is it possible to create an extension function and call it as if it were static?
For Example...
fun System.sayByeAndExit() {
println("Goodbye!")
System.exit()
}
fun main(args: Array<String&...
Yuyuan asked 3/9, 2016 at 18:30
1
© 2022 - 2024 — McMap. All rights reserved.