+ 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
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/
+ 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
+ 12
Same article and almost in the same time! ššā
+ 10
David Carroll
šSimply the best!šŖš»
+ 9
Gordon I think that we can implement Closures in Java 8 using Functional Interface & Lambda expression as David Carroll mentioned.
+ 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.š
+ 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. š¤·āāļø
+ 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
+ 3
you two posted at almost the same time šš
+ 3
Danijel IvanoviÄ What's the saying... simple minds think alike and all that? š¤Ŗ
+ 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.
+ 2
+ 2
thanks in advance Daniel
+ 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 š¤
+ 1
Danijel IvanoviÄ I am not good at Java. Can you provide an example of Java Closures.
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