Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • The only real (non car-based :) example I can remember seeing for static class variables is reference counting:

    public class MyBaseObject {

        public static int REFCOUNT;

        public MyBaseObject() {
            REFCOUNT++;
        }
    }

    public class DerivedObject extends MyBaseObject {

        public DerivedObject() {
            super();
        }

        public static void main(String[] args) {
            for (int i = 0 ; i
    • In other words, my Car example, but without the Car. :)

      Is it common to want to implement reference counting in this way? What's the use case?

      • Doh. Yes, I didn't think that through really, did I?

        I have never used static class variables in Java. They seem like a subtle disaster waiting to happen. Also I try (where possible) to program without side-effects.

        Moreover, Java doesn't have proper destructors, so you can't decrease the count in any reasonable way.

        Is there perhaps a more reasonable use case for a kind of object-level namespace? It would be horrible in practice, but something like public static HashMap MyBaseObject.OBJECT_VARIABLES...

        Sounds like a guarantee of threading problems to me, though.