java-8 Questions
4
Solved
TL;TD In Java 8, is there a way for an interface default method to access instance variables?
For instance:
public interface Foo{
default getBazModified(){
return baz * 2;
}
}
public class B...
7
Solved
In Java 8, I have a variable, holding an optional boolean.
I want an action to be executed, if the optional is not empty, and the contained boolean is true.
I am dreaming about something like ifP...
Repatriate asked 16/10, 2017 at 8:55
6
Solved
I have a class where optionally a Comparator can be specified.
Since the Comparator is optional, I have to evaluate its presence and execute the same stream code, either with sorted() or without...
Loincloth asked 27/7, 2017 at 6:7
7
Solved
I'm working on project with Java 8 and found one situation which I can't understand.
I have code like this:
void deleteEntity(Node node) throws SomeException {
for (ChildNode child: node.getChil...
1
2
Solved
I'm trying to use in place of bitmask below is the code
public static Set<Amenities> fromBitFlags(int bitFlag) {
return ALL_OPTS.stream().filter(a -> (a.ameityId & bitFlag) > 0)....
Ladin asked 3/2, 2016 at 13:23
8
Solved
I am a beginner in using Lambda expression feature in Java 8. Lambda expressions are pretty well useful in solving programs like Prime number check, factorial etc.
However can they be utilized eff...
Dignify asked 2/6, 2015 at 12:16
7
I am in the middle of upgrading my project from Java 8 to Java 17. My project use JAXB related JAR files. However, I am getting a lot of error while compiling the project and most of them are relat...
3
Solved
I don't feel the difference between map() and mapToObj() methods in Java 8 Streams. In both we can create and return objects to the streams, so why these methods exist as two, not only one.
Could ...
Para asked 14/12, 2017 at 7:10
3
Solved
I am writing a parser for a file in Java 8. The file is read using Files.lines and returns a sequential Stream<String>.
Each line is mapped to a data object Result like this:
Result parse(S...
Solo asked 6/11, 2014 at 12:37
7
Solved
Im trying to use Java 8 streams to combine lists.
How can I get a "symmetric difference list" (all object that only exist in one list) from two existing lists.
I know how to get an intersect list a...
Outfoot asked 26/6, 2015 at 13:30
6
Solved
I have an object of ZonedDateTime that is constructed like this
ZonedDateTime z = ZonedDateTime.of(LocalDate.now().atTime(11, 30), ZoneOffset.UTC);
How can I convert it to LocalDateTime at time ...
Lemures asked 16/4, 2018 at 9:33
5
I have a code fragment that I want to make more concise yet readable
using Java 8 features like lambdas/streams etc.
Basically, there is a list of items and each item has a list of errors.
If ther...
Gardia asked 19/1, 2019 at 11:54
3
Solved
What is the difference between JsonIgnore on Field vs JsonIgnore on a getter of a field in Jackson?
12
Solved
Lets say I have a list of words and i want to create a method which takes the size of the new list as a parameter and returns the new list. How can i get random words from my original sourceList?
...
Unblushing asked 29/7, 2015 at 14:20
5
Solved
I am trying to do what seems to be a relatively basic thing in the new JDK 8 land of functional programming, but I can't get it to work. I have this working code:
import java.util.*;
import j...
Qualified asked 11/11, 2014 at 19:21
1
Solved
Consider the following snippet:
public static void main(String[] args) {
Function<String, String> function = String::toUpperCase; //OK
// Comparator<String> comparator = String::toUppe...
Godson asked 31/5 at 7:31
3
Solved
I am trying to convert date 06-12-2015 02:10:10 PM from default zone to UTC using ZonedDateTime.
LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
Z...
Earlineearls asked 6/12, 2015 at 9:14
7
Solved
Is there any significant difference (in performance or best practices) between those two stream creation methods?
int[] arr2 = {1,2,3,4,5,6};
Arrays.stream(arr2)
.map((in)->in*2)
.mapToObj((...
Duester asked 31/12, 2018 at 9:19
8
I am using up-to-date Eclipse Luna which should be ready for Java 8. However when I choose to create a new server with Tomcat 7 and click Next, in the Add and Remove screen I can't move my project ...
Tripedal asked 11/3, 2015 at 19:12
3
Solved
JDK 8 EA is out now, and I am just trying to get used to the lambda and the new Stream API. I've tried to sort a list with parallel stream, but the result is always wrong:
import java.util.ArrayLi...
Circumference asked 22/10, 2013 at 23:14
6
I am trying to have JDK 8 run with cassandra 3.x in my dev-setup Mac with M1Pro Chip. Arm64 jdk-8 is currently unavailable currently.
6
Solved
I am sending result in descending order but I get output with ascending order
List<myEntity> myData = new ArrayList<>();
Map<Integer,List<myEntity>> myid = new LinkedHashMa...
Gonzalez asked 5/9, 2018 at 19:20
2
Please take a look at my code:
Object longL = 2548214;
Map<String, Object> map = new HashMap<String, Object>(1);
map.put("LongNumber", longL);
List<Map<String, Object>> re...
9
Solved
As a non-Java programmer learning Java, I am reading about Supplier and Consumer interfaces at the moment. And I can't wrap my head around their usage and meaning.
When and why you would use these ...
Faruq asked 9/2, 2015 at 19:0
1 Next >
© 2022 - 2024 — McMap. All rights reserved.