I decided to update my JDK to Java 8, and installed to the default location of C:Program FilesJavajdk1.8.0 with a jre subdirectory. I wasn’t sure how Android Studio worked out the JDK location, so I decided to launch it and see. I got the following message: Failed to complete Gradle execution. Cause: Supplied javaHome is not a valid folder. You
Tag: java-8
Can an interface method have a body?
I know that an interface is like a 100% pure abstract class. So, it can’t have method implementation in it. But, I saw a strange code. Can anyone explain it? Code Snippet: EDIT: My IDE is Intellij Idea 13.1. The project SDK is java 7 <1.7.0_25>. The IDE is not showing any compiler error. But, When I compile the code
Implementing two interfaces with two default methods of the same signature in Java 8
Suppose I have two interfaces: If I want to implement both of them, what implementation will be used? Answer This is a compile-time error. You cannot have two implementation from two interfaces. However, it is correct, if you implement the getGreeting method in C1: I just want to add that even if the method in I1 is abstract, and default
Java8 Lambdas vs Anonymous classes
Since Java8 has been recently released and its brand new lambda expressions looks to be really cool, I was wondering if this means the demise of the Anonymous classes that we were so used to. I’ve been researching a bit about this and found some cool examples about how Lambda expressions will systematically replace those classes, such the Collection’s sort
How to work around the stricter Java 8 Javadoc when using Maven
You’ll quickly realize that JDK8 is a lot more strict (by default) when it comes to Javadoc. (link – see last bullet point) If you never generate any Javadoc then of course you’ll not experience any problems but things like Maven release process and possibly your CI builds will suddenly fail where they worked just fine with JDK7. Anything that
Convert java.util.Date to java.time.LocalDate
What is the best way to convert a java.util.Date object to the new JDK 8/JSR-310 java.time.LocalDate? Answer Short answer Explanation Despite its name, java.util.Date represents an instant on the time-line, not a “date”. The actual data stored within the object is a long count of milliseconds since 1970-01-01T00:00Z (midnight at the start of 1970 GMT/UTC). The equivalent class to java.util.Date
Collect successive pairs from a stream
Given a stream such as { 0, 1, 2, 3, 4 }, how can I most elegantly transform it into given form: { new Pair(0, 1), new Pair(1, 2), new Pair(2, 3), new Pair(3, 4) } (assuming, of course, I’ve defined class Pair)? Edit: This isn’t strictly about ints or primitive streams. The answer should be general for a stream
How do I use the new computeIfAbsent function?
I very much want to use Map.computeIfAbsent but it has been too long since lambdas in undergrad. Almost directly from the docs: it gives an example of the old way to do things: And the new way: But in their example, I think I’m not quite “getting it.” How would I transform the code to use the new lambda way
Removing Java 8 JDK from Mac
So I installed the beta of JDK 8 a while ago to look at some of the examples. I thought for sure by now, it’s easy to change between versions. Doing some Play development with IntelliJ. For some reason, IntelliJ is compiling with 8 even though: I have the compiler set in Preferences to use 1.6 Supposedly it’s using SBT
Java 8: Where is TriFunction (and kin) in java.util.function? Or what is the alternative?
I see java.util.function.BiFunction, so I can do this: What if that is not good enough and I need TriFunction? It doesn’t exist! I guess I should add that I know I can define my own TriFunction, I’m just trying to understand the rationale behind not including it in the standard library. Answer As far as I know, there are only