Java nested constructors

Status
You're currently viewing only snotnose's posts. Click here to go back to viewing the entire thread.

snotnose

Ars Praefectus
3,454
Subscriptor
My main constructor does stuff, my 'helper' (sorry, not up on OO terminology) constructors call the main constructor with various defaults:
Code:
public class Broken {
        private int foo;

        Broken() {
            Broken(0);        // Gives 'error: cannot find symbol'
            this.Broken(1); // Ditto
        }
        Broken(int bar) {
            foo = bar;
        }

        private void show(String why) {
            System.out.println(why + foo);
        }

    public static void main(String[] args) {
        Broken b = new Broken();
        Broken b2 = new Broken(42);

        b.show("broken() ");
        b2.show("broken(42) ");
    }
}
Is this forbidden, or am I missing some syntactical sugar?
 
Status
You're currently viewing only snotnose's posts. Click here to go back to viewing the entire thread.