javablackberry

Super constructor call in Blackberry Screen classes


Why is the super() constructor recommended to be called when extending any of the RIM Screen classes? It was my understanding that the no-arg constructor of any super class was implicitly called from any class that extends it, am I wrong?


Solution

  • super() will be called by default constructor no matter if you implement it or not.

    It's easy to test. Just a couple classes:

    class ClassA {
        public ClassA() {
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    Dialog.inform("ClassA()");
                }
            });
        }
    }
    
    class ClassB extends ClassA {
        public ClassB() {
            super();
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    Dialog.inform("ClassB()");
                }
            });
        }
    }
    
    class ClassC extends ClassA {
    
    }
    
    class ClassD extends ClassA {
        public ClassD() {
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    Dialog.inform("ClassD()");
                }
            });
        }
    }
    

    And test app:

    class Scr extends MainScreen {
    
        protected void makeMenu(Menu menu, int instance) {
            super.makeMenu(menu, instance);
    
            menu.add(new MenuItem("class A", 0, 0) {
                public void run() {
                    ClassA a = new ClassA();
                }
            });
            menu.add(new MenuItem("class B", 0, 0) {
                public void run() {
                    ClassB b = new ClassB();
                }
            });
            menu.add(new MenuItem("class C", 0, 0) {
                public void run() {
                    ClassC c = new ClassC();
                }
            });
            menu.add(new MenuItem("class D", 0, 0) {
                public void run() {
                    ClassD d = new ClassD();
                }
            });
        }
    }
    

    So you see, there is no difference between dialog calls in ClassA() and ClassC(), also no diffs between ClassB() and ClassD().