3 ms·
If you can't use pointer arithmetic, you don't use pointers. Your language uses them internally, but not you. NullPointerException in Java/C# is a result of a l
by yetihehe 10y ago
If you can't use pointer arithmetic, you don't use pointers. Your language uses them internally, but not you. NullPointerException in Java/C# is a result of a leaky abstraction.
- bluejekyll 10y agoYeah, they could just as easily have made it a NullException and not lost any meaning. Or better yeah, they could have made a null safe language ;)
- vbezhenar 10y ago> If you can't use pointer arithmetic, you don't use pointers. Is it someone's definition of pointer? > Your language uses them internally, but not you. I'm actively using pointers that point to object. > NullPointerException in Java/C# is a result of a leaky abstraction. I don't agree. Java has uses pointers (which also called references and those are synonyms for Java), Java has concept of null pointer and I don't see why NullPointerException is leaky abstraction.
- yetihehe 10y agoIt is wikipedia[1] definition of pointer. > In computer science, a pointer is a programming language object, whose value refers to (or "points to") another value stored elsewhere in the computer memory using its memory address. > [2] Pointers are the most primitive. Due to their intimate relationship with the underlying hardware, they are one of the most powerful and efficient types of references. Pointer "points to memory", so if you change value of a pointer, you change what memory it points to. In java you can't change what a pointer points to. It's only references. > I'm actively using pointers that point to object. No, you passively use references that point to object. You can't do *(ptr+1) in java. Leaky abstraction means that it's called a pointer but it isn't a real pointer. Also as another commenter said, in C# it's properly called a reference. [1] https://en.wikipedia.org/wiki/Pointer_(computer_programming) https://en.wikipedia.org/wiki/Pointer_(computer_programming) [2] https://en.wikipedia.org/wiki/Reference_(computer_science)#Examples https://en.wikipedia.org/wiki/Reference_(computer_science)#E...
- vbezhenar 10y agoOf course you can change the value of pointer in Java, just assign any other address. Even if I can't do pointer arithmetic in Java, they are still pointers, just without pointer arithmetic.