constructor-reference Questions
2
Solved
code like this
public class LambdaTest {
public static void main(String[] args) {
final Animal animal = Dog::new;
animal.eat();
}
}
@FunctionalInterface
interface Animal {
void eat();
}
clas...
Intromit asked 16/2, 2023 at 9:30
5
Why doesn't the first of the following examples work?
run(R::new); method R.run is not called.
run(new R()); method R.run is called.
Both examples are compiled-able.
public class ConstructorRe...
Brownedoff asked 7/1, 2019 at 10:15
1
Solved
Assume the following code:
class ConstructMe<T> {}
data class Test<T> constructor(var supplier: () -> ConstructMe<T>) {}
fun main(args: Array<String>) {
works<Int&g...
Consider asked 4/6, 2016 at 11:26
2
Solved
Given the following code:
package com.gmail.oksandum.test;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
}
public void foo(...
Ornithomancy asked 8/10, 2014 at 13:40
3
Solved
I learn new features of Java 8.
I am playing with different examples and I have found a strange behaviour:
public static void main(String[] args) {
method(Test::new);
}
static class Test{...
Litterbug asked 21/9, 2015 at 20:25
1
Solved
I am reading Java 8 book, and it comes with a sample I reproduce:
@FunctionalInterface
public interface Action {
public void perform();
}
An Implementor:
public final class ActionImpl implements ...
Koehler asked 21/10, 2014 at 23:13
1
Solved
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.
Voleta asked 20/10, 2014 at 18:51
1
I am creating a supplier for an inner class constructor using the lambda ctx -> new SpectatorSwitcher(ctx). IntelliJ suggested that I change it to SpectatorSwitcher::new instead. SpectatorSwitch...
Plenteous asked 30/3, 2014 at 0:54
1
© 2022 - 2024 — McMap. All rights reserved.