Constructor being called again?

Posted by Halo on Stack Overflow See other posts from Stack Overflow or by Halo
Published on 2010-04-26T12:34:30Z Indexed on 2010/04/26 12:43 UTC
Read the original article Hit count: 238

I have this constructor;

public UmlDiagramEntity(ReportElement reportElement, int pageIndex, Controller controller) {
    super(reportElement.getX1(), reportElement.getY1(), reportElement.getX2(), reportElement.getY2());
    setLayout(null);

    this.pageIndex = pageIndex;
    this.controller = controller;
    reportElements = reportElement.getInternalReportElements();
    components = new ArrayList<AbstractEntity>();
    changedComponentIndex = -1;

    PageListener p = new PageListener();
    this.addMouseMotionListener(p);
    this.addMouseListener(p);

    setPage();
}

And I have an update method in the same class;

   @Override
    public void update(ReportElement reportElement) {
        if (changedComponentIndex == -1) {
            super.update(reportElement);
        } else {
            reportElements = reportElement.getInternalReportElements();
            if (components.size() == reportElements.size()) {
                if (!isCommitted) {
                    if (reportElement.getType() == ReportElementType.UmlRelation) {
                        if (checkInvolvementAndSet(changedComponentIndex)) {
                            anchorEntity(changedComponentIndex);
                        } else {
                            resistChanges(changedComponentIndex);
                        }
                        return;
                    }
                }
..................goes on

When I follow the flow from the debugger, I see that when update is called, somewhere in the method, the program goes into the constructor and executes it all over again (super, pageIndex, etc.). Why does it go to the constructor :D I didn't tell it to go there.

I can make a deeper analysis and see where it goes to the constructor if you want. By the way, changedComponentIndex is a static variable.

© Stack Overflow or respective owner

Related posts about java

Related posts about constructor