+ 6
Without wrap in Java int x = 10; int x = fun(x); int fun(input){ //do something with input return input; } remember that you didn't changed the value, you have created a new int object and the previous int(10) will be garbage collected ! Anyways don't get mad about this .. they are different languages.. Just keep in mind that Java has ownership of everything through hashmaps and like you can read in the comments of this question it is a language design. For example this could help in multithreaded situations. https://stackoverflow.com/questions/5298421/why-doesnt-java-support-pass-by-reference-like-c For js I think it's the same since it takes a lot from java.
7th Jun 2019, 7:57 AM
AZTECCO
AZTECCO - avatar
+ 5
I must admit kumesana had a good point! rudolph flash ... my friend.. I appreciate your approach and effort to understand everything! This is a core design of the language and I think it's really important to catch it, it would make the difference! I'm gonna study it since I haven't really caught it but it's interesting! If you guys find something let me know please
7th Jun 2019, 9:18 AM
AZTECCO
AZTECCO - avatar
+ 3
In JavaScript I never encountered a situation where I needed PBR . In Java probably I won't too
7th Jun 2019, 7:59 AM
AZTECCO
AZTECCO - avatar
+ 2
Fundamentally, it is better to rethink your logic flow to do it another way.
7th Jun 2019, 7:52 AM
kumesana
+ 2
You said "if we need our own 'swap' then without this we cannot do it." Sure, **if** we need such a thing. But that way to put it is ignoring a very important and fundamental truth: we **don't** need our own 'swap'. We never will. A 'swap' method is fundamentally not something that is in any way helpful, let alone needed. I have been there before you, and you're confusing "cool" with "needed". I get it. It feels cool, the idea that you can make a swap method, and then with it, you can swap variables whenever you'll want. Cool, maybe. That factor wears off with time when the language structures loses its novelty. But useful in any way whatsoever, no. There won't be a case where that would be useful. Try and find one, I am very confident that you never will. There will always be different ways to do the things you would have done with a 'swap' method, and some of these other ways will be fundamentally better. Clearer code, more organized. There will be nothing but benefits. I'm sure you will try to find counterexamples. But that is bound to fail. One reason for this is one of the rules that prove true in programming: side-effects always degrade code quality. Avoiding them is always better.
7th Jun 2019, 8:38 AM
kumesana
0
We don't need to do our own swap.
7th Jun 2019, 8:07 AM
kumesana