Page 1 of 1

Using Object class as a method parameter

Posted: Fri Aug 07, 2009 2:17 pm
by ConvertFromOldNGs
by Joseph O'Dwyer >> Fri, 6 Aug 1999 3:21:33 GMT

Why when I use an Object class as a method parameter does the JADE compiler not allow me to pass in any class inherited from the Object class.

For example

On the Form class is the following method signature

processFormChanges (aObject : Object io) : String updating;

Another object invokes this method using the following;

lForm : Form;
lUser : User;

lForm.processFormChanges(lUser);

The JADE compiler traps this as a "Error 6071 - Incompatible paramter type".

I have since defined the method using an Any datatype but am not sure why an Object type does not work.

Thanks

Joseph

Re: Using Object class as a method parameter

Posted: Fri Aug 07, 2009 2:17 pm
by ConvertFromOldNGs
by Craig Shearer >> Fri, 6 Aug 1999 10:28:35 GMT

Hi Joseph

The problem you are having is with the io parameter. When you pass an io parameter, you are saying to the compiler that your method might change the reference, ie. your method might make the parameter you pass in point to a completely different object.

Because of this, the object reference you pass in must be the exact type that you specify in the method signature. Since Object is an abstract class, it's impossible to have an object whose class is Object, therefore no parameter you pass is a compatible parameter type!

I would ask whether you need to have an io parameter - can it be input, or output or even constant? In my experience, some JADE developers tend to use io parameters even when they're not required, simply as a fix for the compiler message "cannot update constant" when they should be using an input parameter instead.

Hope this helps,
Craig.