Latest Questions tagged Java 8

Browse all latest questions tagged Java 8

Published 19 Sep, 2022
Java - Java 8 Unsafe: xxxFence() instructions

In Java 8 three memory barrier instructions were added to Unsafe class (source): /** * Ensures lack of reordering of loads before the fence * with loads or stores after the fence. */ void loadFence...

Published 27 Oct, 2022
Java - How to replace only the first element of a List<Character> using java streams without making any changes to the rest of the list?

I am getting a List and I want to replace the first value in this list with '$' sign, So that I could use it in some place else. But i don't want the rest of the characters in the list to be misplaced...

Published 19 Sep, 2022
Java - Java access bean methods with LambdaMetafactory

my question is strongly related to Explicit use of LambdaMetafactory in that thread, some very good examples are provided to use the LambdaMetafactory to access a static method of a class; however, I...

Published 19 Sep, 2022
Java - Java 8 method references and overridden methods

I've been using lambdas and method references in Java 8 for a while and there is this one thing I do not understand. Here is the example code: Set&lt;Integer&gt; first = Collections.singleton(1);...

Published 07 Sep, 2022
Java - Using streams to collect into TreeSet with custom comparator

Working in Java 8, I have a TreeSet defined like this: private TreeSet&lt;PositionReport&gt; positionReports = new TreeSet&lt;&gt;(Comparator.comparingLong(PositionReport::getTimestamp));...

Published 14 Sep, 2022
Java - Difference between java 8 streams and parallel streams

I wrote code using Java 8 streams and parallel streams for the same functionality with a custom collector to perform an aggregation function. When I see CPU usage using htop, it shows all CPU cores be...

Published 15 Oct, 2022
Java - Filter a list with streams based on ids from another list

I have a list of Product objects with 30 objects. I have created a fix list with strings of ids. List&lt;String&gt; productsIdsForFreeSchoolYear = Arrays.asList("169", "172", "198", "213", "358", "4...

Published 15 Sep, 2022
Java - SonarQube on Java8-project gives jacoco-Exception

I just downloaded the latest version, SonarQube 4.3, then try build a java-8 project with: mvn clean install mvn sonar:sonar That gives me the Exception below. Googling, I got the impression...

Published 15 Sep, 2022
Java - "A JNI Error has occurred" for one instance of the program, not for another

I made a large program in Eclipse Java Mars on one computer which worked fine. I exported the program as a runable Jar-file and running it gave no problem whatsoever. Even when I exported the entire p...

Published 12 Oct, 2022
Java - How to test whether the object has been modified using Junit?

I have a method. void (Item item) { } I want to test in Junit whether item has been modified or not. Can some one tell me how do I do that ?

Published 06 Sep, 2022
Java - Shuffle/Random comparator

IS there any way to emulate the behavior of Collections.shuffle without a comparator being vulnerable to the sorting algorithm implementation for the result to be safe? I mean not breaking the compar...

Published 20 Oct, 2022
Java - Java 8 stream and set attribute from call Boolean method

Please can you help me resolve this issue I am having when attempting to stream through an array list and call a setter based on a method which returns a Boolean. Written as a for loop, it would look...

Published 05 Sep, 2022
Java - Jackson. Deserialize missing properties as empty Optional<T>

Let's say I have a class like this: public static class Test { private Optional&lt;String&gt; something; public Optional&lt;String&gt; getSomething() { return something; } p...

Published 01 Sep, 2022
Java - Optional vs if/else-if performance java 8

Hello i have two samples of code if/else if/else statements private Object getObj(message) { if (message.getA() != null) return message.getA(); else if (message.getB() !=...

Published 06 Sep, 2022
Java - Benefit of using Java Function rather than normal method?

The Function Interface is introduced in Java 8, to implement functional programming in Java. It represents a function that takes in one argument and produces a result. It's easy to practise and read,...