Questions tagged [function-reference]
20 questions
145
votes
1 answer
Are there constructor references in Kotlin?
In Java we have the Class::new syntax for constructor references. I know, there are callable references for methods, but how about constructors? A typical use case for me would be factories.

Kirill Rakhman
- 42,195
- 18
- 124
- 148
9
votes
1 answer
Can I get a function reference to a function with default parameters in Kotlin, as the parameterless function?
Is it possible to get a function reference to a function which has default parameters, specified as the parameterless call?
InputStream.buffered() is an extension method which transforms an InputStream into a BufferedInputStream with a buffer size…

Zymus
- 1,673
- 1
- 18
- 38
7
votes
1 answer
How can I reference an existing method in Raku?
As explained in the docs, you can reference an existing function by prepending the & sigil:
&say # reference to the `say` function
&infix:<+> # reference to the infix `+` operator
How do I do this for methods?

uzluisf
- 2,586
- 1
- 9
- 27
3
votes
0 answers
What is the difference between rvalue and lvalue references to functions?
From c++11 onwards, there are lvalue and rvalue references. I am aware of the differences between them. However, akin to function pointers such as int(*fptr)(), c++ also has lvalue and rvalue references to functions int(&lvalue)() and…

LoquaciousLlama
- 31
- 2
2
votes
1 answer
Making a reference to set type functions in Java
I'm making a generic abstract class that will work with float and integer values and will use different algorithms to generate a new value. It relies heavily on picking a random value within range, so I wanted to make a generic RandomRange kind of…

Vlad Vyatkin
- 544
- 5
- 16
2
votes
2 answers
Passing References to Member Functions
I've been working with a doubly-threaded BST in C++, and I thought it would be cool to separate my visitor functions from my various traversals. However I can't figure out how to properly pass references to member functions into my traversal…

ToTheStars_1138
- 48
- 5
2
votes
1 answer
std::bind on operator[] of std::array
I am trying to bind a member function at or operator[] of std::array, but the compiler (gcc 7.3) says that it can't determine the typename _Func. So I had created my own struct array to see where the problem is. But it works fin in this…

Tom
- 23
- 3
2
votes
2 answers
How new operator works with delegates in C#
In this code snippet how does new MyDel(this.WelcomeUser) work? What happens in memory, I know that delegate is reference type, so is there an object created in heap and which type of object is it - MyDel? what is exactly this.WelcomeUser? Is it a…

Grigoryants Artem
- 1,401
- 2
- 15
- 32
2
votes
1 answer
Difference between calling a function in a lambda and function references
In the following code (in kotlin)
fun greet(){
print("Hello! ")
}
fun salute(){
print("Have a nice day ")
}
fun main(args: Array){
//val todoList: List<()->Unit> = listOf(::greet,::salute)
val todoList: List<()->Unit> =…

KansaiRobot
- 7,564
- 11
- 71
- 150
1
vote
1 answer
Taking Python class method as a polymorphic function
Edit: this question is based on two mistakes: not originally yincluding self in methods and assuming unbounded methods would not exhibit polymorphism, but they do. I voted to close it.
I can take a method as a function-valued object in Python:
class…

user118967
- 4,895
- 5
- 33
- 54
1
vote
1 answer
Cross referencing between different *.py files possible?
My program tui.py consists of about 70 functions, which are sorted groupwise into four different documents:
tui.py
tbt.py
ens.py
hmm.py.
Most functions call at least one other function, some also call a function located in another *.py file.
I…

Nepumuk
- 243
- 1
- 3
- 13
1
vote
1 answer
in kotlin how to put function reference in an array
Having class member function like:
private fun getData1(uuid:String): IData? {
...
}
private fun getData2(uuid:String): IData? {
...
}
private fun getData3(uuid:String): IData? {
...
}
and would like to put in a function reference…

lannyf
- 9,865
- 12
- 70
- 152
0
votes
0 answers
Rebuild error in android kotlin code java.lang.noSuchMethodError?
While trying to build an existing source code in android, I got an error like this.
Error: cannot generate view binders java.lang.NoSuchMethodError: 'void kotlin.jvm.internal.FunctionReferenceImpl.(int, java.lang.Class, java.lang.String,…

Priya R G
- 543
- 4
- 10
- 21
0
votes
1 answer
C++ Reference to member function work around (computation speed)
It is well known that you cannot create a reference to a member function in C++ [source].
For those that don't know. The issue come when you want to do something similar to
class A
{
public:
void Add(int a, int b)
{
std::cout << "Sum…

João Viana
- 31
- 1
- 5
0
votes
1 answer
Prompting for user input as part of a reference to an out-of-script function in R
I have an issue similar to the one described in this post however mine involves a function being called in script 1 from a second script that stores the function. Essentially script1.R has reference to foo() in script2.R and inside foo() I have a…

BLP92
- 145
- 2
- 10