Skip to main content
Filter by
Sorted by
Tagged with
3 votes
3 answers
137 views

I’m working on a simple Swing GUI in Java and have a method addListeners() where I attach an ActionListener to a button like this: increase.addActionListener(this::increasePoints); However, this line ...
jamesdiaz's user avatar
  • 137
1 vote
2 answers
64 views

I am trying to build a data-grid library by wrapping ag-grid, so that if client decides to change ag-grid to some other library we dont have to work on multiple pages on refactoring. We can just make ...
Bopsi's user avatar
  • 2,526
0 votes
1 answer
105 views

I am trying to convert the below null check of legacy java 7 code to modern java using Streams and Optional. if (person != null) { System.out.println(person.getName()); System.out.println(person....
purbarunc's user avatar
1 vote
2 answers
121 views

Consider the following contrived "hello, world": abstract public class Main implements java.util.function.Supplier<Runnable> { public static void main(String[] args) { new ...
stefanobaghino's user avatar
0 votes
2 answers
187 views

I'm learning about Java Threads and I've encountered two different ways to create a thread. I'm not sure about the technical differences between them: // Approach 1 Thread n = new Thread(new ...
happy's user avatar
  • 515
2 votes
2 answers
117 views

I've been trying to hack a bit around this very ugly looking piece of code in my codebase. The original code looks like this: Long variable = Optional.of(message) .map(Message::getPayload) ....
Heribert Greinix's user avatar
-2 votes
1 answer
102 views

Stream.anyMatch is defined as: boolean anyMatch(Predicate<? super T> predicate) I created a new Class as follows: class ClassA { public boolean anyMethodName(Object o) { return ...
user1169587's user avatar
  • 1,448
12 votes
1 answer
684 views

Consider the following snippet: public static void main(String[] args) { Function<String, String> function = String::toUpperCase; //OK // Comparator<String> ...
Rohan Jaiswal's user avatar
2 votes
1 answer
111 views

I did some tests in Groovy3 and Java lambda expressions are mostly interpreted as closures instead of as Functional Interface instances. How can I make lambdas work with Generics in a practical way (...
Fred's user avatar
  • 33
0 votes
1 answer
405 views

I'm facing issue with method reference and type inference. Parent class that returns T type : public class Parent { public <T extends Parent> T get() { ... } } The following ...
kahn's user avatar
  • 55
0 votes
0 answers
38 views

I've read about this but I haven't found a clear answer. Assume an API like the following: Callback callback = new Callback(); myApi.addCallback(callback); [...] myApi.removeCallback(callback); Now, ...
user1831114's user avatar
-1 votes
1 answer
119 views

I am trying to use method references with generic classes and have noticed that I can make it work with the equivalent lambda expression, but not with method references. I'm wondering if someone can ...
PVDM's user avatar
  • 118
1 vote
1 answer
301 views

I have a method reference (represented by the kotlin.reflect.KFunction0 interface). What I would like to do is to get the receiver object of the method reference. For example: data class MyClass(val ...
Martin Häusler's user avatar
1 vote
0 answers
57 views

In the following Java code, PropertyChangeListener is implemented in two ways: 1) using a class that implements PropertyChangeListener interface, and 2) using a method reference. According to the API, ...
user153245's user avatar
0 votes
1 answer
81 views

I have started using the method reference operator :: in java. I am basically adding a Clipboard listener to the clipboard manager like this: this.clipboardManager.addPrimaryClipChangedListener(...
zaxunobi's user avatar
  • 962
0 votes
1 answer
123 views

public static class MyClass { public String methodS(UnaryOperator<String> fn) { return fn.apply(""); } public Integer methodI(UnaryOperator<Integer> fn) { ...
user1589188's user avatar
  • 5,778
0 votes
0 answers
132 views

In the following code, @CompileStatic does not work in combination with the method reference operator for Groovy methods collect and find, although it works with Java streams or the method pointer ...
IWilms's user avatar
  • 600
1 vote
3 answers
434 views

I have a std::vector<std::vector<int>>, from which I want to check whether there is at least 1 sub-vector that's empty. So I have this: std::any_of(vec.begin(), vec.end(), [](const auto&...
Jack Sack's user avatar
-3 votes
1 answer
262 views

Sonar is throwing code smell at the below lines: File file = new File(xxxxxx); Arrays.stream(file.listFiles()).map(path->path.getName()).collect(Collectors.toList()).toString(); I already ...
Selenium New bie's user avatar
0 votes
1 answer
63 views

public static void main(String[] args) { Student[] students = new Student[4]; students[0] = new Student("guy1", 103, 334); // height / age (randomly written) students[...
Clarence's user avatar
0 votes
0 answers
92 views

i'm trying to understand some scenario i ran into related to method-reference. i have a method that create an object and then return a method reference based on that object. when the function ends, ...
jen's user avatar
  • 3
0 votes
3 answers
315 views

I am working with Java Spring framework and JWT - Java Web Tokens. I have below class import java.util.function.Function; import org.springframework.security.core.userdetails.User; import org....
user1887464's user avatar
1 vote
1 answer
141 views

I am learning method references in Java 8. I learnt that we can define functional interface method with either lambda or method reference. Method reference is a way of telling "there exist a ...
J. Doe's user avatar
  • 1
0 votes
0 answers
23 views

I have a bunch of methods, with similar signatures, compatible with Function, they each declare throws InterruptedException, and I put them in a list and select one by its index and call its apply(). ...
davidbak's user avatar
  • 6,098
-1 votes
1 answer
120 views

Why i cant use StringBuilder::reverse in as method reference to reverse a string? please help make me understand whats going on under the hood. import java.util.ArrayList; import java.util.Arrays; ...
LakshayGMZ's user avatar
3 votes
2 answers
153 views

I am confused about the following line: Seq<String> s1 = seq.zip(split, Function::apply); In this snippet: static String underscoreToCamel(String str) { UnaryOperator<String> ...
Osiris's user avatar
  • 33
1 vote
2 answers
562 views

Java 8+ allows assigning method references to Functional Interfaces. Then what is the problem with below code (jdoodle link) - public void newMethod(){ Predicate p = String::isBlank; } ...
samshers's user avatar
  • 3,780
1 vote
2 answers
173 views

I have the following code: class Result { public Result(long infiniteCount, DoubleSummaryStatistics statistics) { this.infiniteCount = infiniteCount; this.statistics = statistics; ...
traveh's user avatar
  • 2,934
-1 votes
1 answer
133 views

IntStream.iterate(0, i -> i + chunkSize) .limit((long) Math.ceil((double) input.length / chunkSize)) .mapToObj(j -> Arrays.copyOfRange(input, j, j + chunkSize > input....
Vibhanshu Jha's user avatar
-1 votes
2 answers
217 views

I am trying to use a list of function references as a lookup table (avoiding the need for a long switch statement). The code worked for a list of static methods, but when I tried to use non-static (i....
ThePythonator's user avatar
0 votes
1 answer
47 views

I have similar lines of code batchPrice1 = items.stream() .map(CommodityItem::getTotalPrice1) .reduce(ZERO, BigDecimal::add); batchPrice2 = items.stream() ...
Володимир's user avatar
0 votes
1 answer
494 views

I have the following domain classes: public class Task { private Project project; } public class Project{ private int id; } And I have a list of tasks called tasks. I would like to group ...
Samet DAĞ's user avatar
3 votes
2 answers
604 views

I want to pass a property getter method reference as one of the function arguments, and have that argument be of my own functional interface type, but ran into an issue. Here's a stripped down minimal ...
Quinteger's user avatar
  • 193
-4 votes
1 answer
96 views

I am curious as to how the below code compiles @Bean(name = "ErrorDecoder") public ErrorDecoder streamHubErrorDecoder() { return FeignException::errorStatus; } The type of ErrorDecoder ...
Veeraraghavan N's user avatar
3 votes
2 answers
771 views

I'm learning Java 8 with Lambda, Streams, and method reference. Regarding the example below, Optional<String> s = Optional.of("test"); System.out.println(s.map(String::toUpperCase).get(...
elvis's user avatar
  • 1,286
1 vote
1 answer
101 views

I am working with a large data structure where I want to perform a series of stream operations of the pattern: <some stream> .map(<method reference getter that returns List>).filter(...
Dan Birmingham's user avatar
-1 votes
1 answer
288 views

I'm learning Java lambdas for school, and I am stuck for a couple of days now. Background I have a list of pumps which I have to sort out on power, last revision, … I already wrote a Comparator that's ...
S.Cl's user avatar
  • 1
-2 votes
1 answer
302 views

I'm coming from a JavaScript background and I'm seeing the :: operator for the first time. I understand what it does, but I'm wondering why it's necessary. In JavaScript, something like this is ...
NoBullsh1t's user avatar
4 votes
1 answer
481 views

I'm facing an odd issue import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collection; import java.util.function.Function; import java....
Marian Klühspies's user avatar
0 votes
0 answers
67 views

Codelens in Visual Studio is great, but I've inherited a code base where some methods are invoked via reflection. This is a simplified sample. ... if (method.Name.EndsWith("UpdatePlatformModel&...
Charlie P's user avatar
0 votes
1 answer
742 views

I'm trying to set up a enum where each Enum value has a custom method to be called. However, it tells me that the method must be static. Is there a way to reference a non-static method? My code ...
Peter Kronenberg's user avatar
1 vote
3 answers
463 views

I have the code snippet below. But i was wondering how to try catch exception with method references. I want to write try catch block for getUserByUserId method, probably log it and catch with ...
Deepak's user avatar
  • 57
1 vote
0 answers
236 views

I'm encountering some weird behavior when passing overloaded method references to a method overloaded with a Function and Supplier variant: public class OverloadedMethodReferenceToOverloadedMethod<...
superbadcodemonkey's user avatar
0 votes
1 answer
54 views

Java List type does not have a getSize() method. Is there a way to tell reference the size() method in EL instead? I've tried #{aList.size > 10} but that is not working.
eastwater's user avatar
  • 5,808
1 vote
1 answer
173 views

I was expecting these to be simple drop-in replacements for each other, but they're not. Clearly I'm not understanding the notation. Can anyone explain why does that happen? playButton.setOnAction(e -&...
scripta's user avatar
  • 121
2 votes
1 answer
80 views

Flink version is 1.10.0 codes as follow: public class WorkerOnlineStatusRun { private static String datahubEndpoint = GlobalParameter.getPublicEndpoint(); private static String redisServer = ...
kursk.ye's user avatar
  • 559
0 votes
2 answers
75 views

Set<String> premiumStrings = new HashSet<>(); Set<String> sortedSet = new TreeSet<>(Comparator.comparing(premiumStrings::contains).thenComparing(Comparator.naturalOrder())); ...
H.v.M.'s user avatar
  • 1,746
1 vote
1 answer
419 views

In the following example (also on Kotlin Playground), IntelliJ offers to change the lambda (as in the commented-out first line of main) to a method reference (as shown in the second line of main). fun ...
k314159's user avatar
  • 12.4k
-1 votes
1 answer
148 views

Interface public interface InterfaceOne { void start(); void stop(); } Main Class public class MainProg { public static void main(String [] args){ new ServiceA().start(); } } ...
Programming-Lover's user avatar
2 votes
1 answer
175 views

The first assignment below doesn't compile, but I am not sure why, the method signature of the static method matches the functional method signature albeit it is not using type arguments. The second ...
SR Bhaskar's user avatar

1
2 3 4 5
12