I am encoding IntelliJ IDEA. When debugging my application, I cannot use some implementations of the default methods in the clock.
Here is a condensed example:
public class Friendship { interface Friend { default void sayHiTo(Friend friend) { System.out.println("Hi, " + friend.hashCode()); } default int amountOfHands() { return 2; } } public static class BasicFriend implements Friend { int numberOfFaces() { return 1; } } public static void main(String[] args) { System.out.println("Put a breakpoint here"); } }
In the main() method, I set a breakpoint and set three hours:
// Default interface method with dependency new BasicFriend().sayHiTo(new BasicFriend()) // Default interface method without dependency new BasicFriend().amountOfHands() // Class method new BasicFriend().numberOfFaces()
The first hours throw a NoSuchMethodException , complaining that the Friendship$BasicFriend.sayHiTo() method does not exist.
The second hour is successful, but, strangely enough, it reports the boxed object { java.lang.Integer@537 } "2" instead of a simple primitive 2 .
The third chat reports primitive 1, as expected.
Why don't the first hours work? This is mistake? Is this related to the IDE? Is it because of some kind of conceptual error of the default methods? Should it work as I want in the first place? Is the strange result of the second shift somehow related to the problem in the first hours?
source share