+ 3

Need Help With Progressing Little By Little Every Day Series #7 of 8

Iā€™m attempting to implement a closure as stated in this post, but it assumes that youā€™re using JavaScript and Iā€™m attempting this with Java. Unfortunately, Iā€™m not sure if what I added to my code is actually a closure, and my code wonā€™t run. https://www.sololearn.com/post/91113/?ref=app https://code.sololearn.com/caL5sdgcnnZO/?ref=app

9th Aug 2019, 10:27 PM
Samuel
Samuel - avatar
16 odpowiedzi
+ 6
Samuel Interesting... But first... Disclaimer: I'm quite vocal about how I feel about Java failing to live up to its potential and is, in my opinion, quite inferior to C# and Kotlin. Any time I look at or write Java code, I feel like I'm working on some legacy system that is 20 years outdated. That said, Java might have limited support for closures using lambdas. However, I believe that the enclosed values within a Java closure cannot be mutated and is therefore readonly. This is unlike what is possible in Javascript or C#. Here's a simple example I implemented in C# based on another person's attempt. https://code.sololearn.com/c6tk7Xsj3FMS/
10th Aug 2019, 7:38 AM
David Carroll
David Carroll - avatar
+ 12
Gordon Check this out! šŸ˜‰ How JavaScript's closures can't be directly used in Java 8 and how it can be simulated by object references. Java 8 Lambda Limitations: Closures ā€” https://dzone.com/articles/java-8-lambas-limitations-closures
10th Aug 2019, 3:22 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 12
Same article and almost in the same time! šŸ˜„šŸ˜āœŒ
10th Aug 2019, 4:09 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 10
David Carroll šŸ˜ŠSimply the best!šŸ’ŖšŸ»
10th Aug 2019, 5:15 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 9
Gordon I think that we can implement Closures in Java 8 using Functional Interface & Lambda expression as David Carroll mentioned.
10th Aug 2019, 10:40 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 9
Gordon Sorry friend, but I haven't done any such example, I really haven't encountered this kind of features, if I do it I'll let you know.šŸ‘
10th Aug 2019, 2:35 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 4
Gordon Have at it man... https://dzone.com/articles/java-8-lambas-limitations-closures Then, compare it to the C# code I posted. The problem with closures in Java is the lack of support for delegates to work with functions as objects. Using interfaces doesn't really cut it. So, in Java, it's very limited support. šŸ¤·ā€ā™‚ļø
10th Aug 2019, 3:20 PM
David Carroll
David Carroll - avatar
+ 4
Considering the author had to go as far back as 2003 to some archived discussion board response about Scheme, it's a bit of a stretch to use as a quote for an article written in 2017. Just sayin'. šŸ˜‰ http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
10th Aug 2019, 4:14 PM
David Carroll
David Carroll - avatar
+ 3
you two posted at almost the same time šŸ˜‚šŸ˜‚
10th Aug 2019, 3:25 PM
Gordon
Gordon - avatar
+ 3
Danijel Ivanović What's the saying... simple minds think alike and all that? šŸ¤Ŗ
10th Aug 2019, 4:16 PM
David Carroll
David Carroll - avatar
+ 3
Stuart Butler Here is the first item in that series: https://www.sololearn.com/post/105678/?ref=app Checkout the many other great posts in the link below for everything.js. https://www.sololearn.com/Profile/13601090/?ref=app Ultimately, that feed wouldn't be anything without the amazing efforts of Gordon.
14th Aug 2019, 6:59 AM
David Carroll
David Carroll - avatar
10th Aug 2019, 5:26 AM
Gordon
Gordon - avatar
+ 2
thanks in advance Daniel
10th Aug 2019, 2:38 PM
Gordon
Gordon - avatar
+ 2
I scrolled through the dzone article and come across this : `"When will you learn? Closures are a poor man's object." ---Ā Anton` <--- What do you think about this statement? According to his perspective, JavaScript Closures is no longer need now because we have class syntax šŸ¤”
10th Aug 2019, 3:28 PM
Gordon
Gordon - avatar
+ 1
Danijel Ivanović I am not good at Java. Can you provide an example of Java Closures.
10th Aug 2019, 1:06 PM
Gordon
Gordon - avatar
0
Sorry this is not an answer but a further question- can you post the link to the 'little by little' series as I can't find it? Thanks
12th Aug 2019, 9:57 AM
Baobab Bingo
Baobab Bingo - avatar