+ 6

Why java does not supprt call bh reference and pointers??

https://code.sololearn.com/cugTB44Z3n3a/?ref=app

9th May 2017, 9:03 AM
Sam Shanmukh
Sam Shanmukh - avatar
4 odpowiedzi
0
No pointers supported in Java, which (may?) would be needed for that (unless a compiler workaround, maybe). So, why no pointers? There are some hacky tool included in Java, so you can do similar stuff, like allocate bytes, and cast them to be a certain object of a type. These unsafe stuff included in the mysterious sun.misc.* package, and highly NOT RECOMMENDED to use. Java developers (I mean Oracle) use the package for themselves, but professional programmers started to use it in special cases. Oracle dislikes this, and wished to remove the utility, then the community answered like "Hell, NO!" It is really a complex question, because Java is said to be one of the safest programming languages, and so, the manual use of pointers is - as all if us know - can be dangerous, allocating memory (and freeing it) "by hand" is the main reason of that. You can read more on the current situation here: https://adtmag.com/blogs/watersworks/2015/08/java-9-hack.aspx?m=1 All that is said, reference parameters (like ref params in C# or pointers in C++) are completely unsupported in Java, afraiding of illegal pointers, I think (pointing to memory, which was allocated, but not aready). For that, you must use reference of objects, which wraps values, exactly like in your code.
13th May 2017, 10:15 AM
Magyar Dávid
Magyar Dávid - avatar
+ 6
Because java virtual machine manage memory for program itself and programmer can only give hint to deallocate memory but using pointers memory management is much in the hand of programmer.
9th May 2017, 9:18 AM
Vaibhav Sharma
Vaibhav Sharma - avatar
+ 5
Do check out the attached program with the question...
9th May 2017, 9:24 AM
Sam Shanmukh
Sam Shanmukh - avatar
13th May 2017, 12:21 PM
Magyar Dávid
Magyar Dávid - avatar