Skip to content
Advertisement

Tag: java-8

CompletableFuture from Callable?

Today I experimented with the “new” CompletableFuture from Java 8 and found myself confused when I didn’t find a runAsync(Callable) method. I can do it myself like shown below, but why is this (to me very obvious and useful utility method) missing? Am I missing something? Answer You are supposed to use supplyAsync(Supplier<U>) In general, lambdas and checked exceptions do

Java 8 filter with method call

I am learning Java 8 lambda and streams and trying some examples. But facing problem with it. here is my code Am getting compilation error in .map addr(second argument) field. what wrong in it and could you please provide links to learn java 8 streams. FYI am following this link Java 8 lambda Answer The first problem is that map

What’s the difference between ZonedDateTime and OffsetDateTime?

I’ve read the documentation, but I still can’t get when I should use one or the other: OffsetDateTime ZonedDateTime According to documentation OffsetDateTime should be used when writing date to database, but I don’t get why. Answer Q: What’s the difference between java 8 ZonedDateTime and OffsetDateTime? The javadocs say this: “OffsetDateTime, ZonedDateTime and Instant all store an instant on

Why does Stream.allMatch() return true for an empty stream?

My colleague and I had a bug that was due to our assumption that an empty stream calling allMatch() would return false. Of course, it is kind of our fault for assuming and not reading documentation. But what I don’t understand is why the default allMatch() behavior for an empty stream returns true. What was the reasoning for this? Like

How to sum a list of integers with java streams?

I want to sum a list of Integers. It works as follows, but the syntax does not feel right. Could the code be optimized? Answer This will work, but the i -> i is doing some automatic unboxing which is why it “feels” strange. mapToInt converts the stream to an IntStream “of primitive int-valued elements”. Either of the following will

Error:java: javacTask: source release 8 requires target release 1.8

Using IntelliJ IDE can’t compile any projects. Screenshots of settings below: Used JDK: Project SDK and Language level: Language Level: Anybody have any ideas? Answer Go to File > Settings > Build, Execution, Deployment > Compiler > Java Compiler If on a Mac, it’s under Intellij IDEA > Preferences… > Build, Execution, Deployment > Java Compiler Change Target bytecode version

Advertisement