There are many concepts involved in Java Challenge! In essence, we will explore lambdas and the Function interface the most. However, we also have static methods introduced in Java 8 the private method in interfaces introduced in Java 9. In the invocation of the interface methods, we are using anonymous inner classes too!
Are you ready for this Java Challenge? Less introduction, more action, try out this Java Challenge, and master Java concepts by having fun!
If you want to watch the video explanation, check it out (But I recommend trying out the Java Challenge first):
That’s it challenger, rock on! Keep taking action and relentlessly break your limits! Don’t hesitate to leave a comment with a question if anything is not clear!
Hi Rafael!
I enjoy your challenger a lot!
However I think there’s something that you should needs clarification in your text. In the video you glance about it but the point I think is lost: Private method can’t be overriden! To be able to override something you need to have access to it. It doesn’t matter if it’s in an interface or if it’s default or in a class. If you try to use the @Overriden you’ll see that the compiler will let you know this.
So what’s happening is that from the point of view of the Jedi Interface when it calls useForce(), it would call the method defined in the interface since the method is never overriden in another class. I guess this is a form of shadowing.
In the video when you change it to public default, then it prints X because the anonymous class has access to it and it can be truly overriden.
As I said, I really enjoyed your puzzler!
Hi Carlos, thanks a lot for your kind words! Also, I highly appreciate your detailed overview of this Java Challenge!
A private method can’t be overridden, that’s it! Interesting point about shadowing, it might be a kind of method shadowing.
When the method is public then we can override, yes!
Thanks for your thoughtful comment again!