3 ms·
You can do the same with statics in Java
by cheeze 4y ago
You can do the same with statics in Java
- kelnos 4y agoNot with that syntax. That syntax declares 'bar' as an instance variable. and 'foo' there is a null pointer, so trying to dereference it like that should produce a NullPointerException. Sure, you could change the declaration of 'bar' to include 'static', and change the access of 'bar' from 'foo.bar' to 'Foo.bar', but... that's not what the code says.
- twic 4y agoI think you can do the same in C++, or at least something very similar. If a method isn't virtual and doesn't touch the object's fields, you can invoke it on null quite happily. Doesn't Go do this too?