Solved

Override method problem - StackOverflowError

Posted on 2013-05-14
2
222 Views
Last Modified: 2013-05-14
I have classes like so:
public class ParentClass {
    private Object myObject;

    public void setMyObject(final Object object) {
	this.myObject = object
    }
}

public class ChildClass extends ParentClass {
    @Override
    public void setMyObject(final Object object) {
        setMyObject(object);
        // do other stuff
    }
}

Open in new window


I want to override the method so that I can do some things not in the parent class method, but first I have to make sure that myObject gets set. As it is, this code gives a StackOverflowError because ChildClass.setMyObject() is called ad infinitum. I cannot change the access of myObject to protected. How is this done?
0
Comment
Question by:allelopath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 16

Accepted Solution

by:
Valeri earned 500 total points
ID: 39165042
you have to invoke the method of the parent class in this way:

super.setMyObject(object);
0
 
LVL 16

Expert Comment

by:Valeri
ID: 39165050
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question