Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Why can't I overload my methods?

Started by aidan_walsh Mar 9, 2004 at 3:31 AM 2 replies 300+ views
Original Post
aidan_walsh
aidan_walsh
public class FileStructure
{
  public void addDirectory(File root, boolean subfolders) throws
      InvalidDirectoryException
  {
    //...
  }


  public void removeDirectory(File root)
  {
    //...
  }


  public boolean updateFileStructure()
  {
    //...
  }


  public Vector describe()
  {
    //...
  }

  public DefaultMutableTreeNode describe()
  {
    //...
  }

  private class InvalidDirectoryException extends Exception
  {
    public InvalidDirectoryException()
    {

    }
  }
}
 
When I try to compile this class (using jdk1.4.2) I keep getting an error telling me that describe() has already been defined. But I know that its possible to create more than one method of the same name in a class... Why isn''t it working here??? Thanks in advance...

SketchSoft OFFLINE | SketchNews OFFLINE | NewKlear Studios

www.aidanwalsh(.net)(.info)
SiCrane
SiCrane
Overloaded methods have to differ by more than just a return type. If you want two functions with the same name that return different types then they need to take different parameters as well.
Eskhan
Eskhan
Java cannot distinguish different methods by return type alone, to properly overload a function you need to supply the function with different parameters.

--------------------
Though this program be madness, yet there is a method in''t
--------------------Though this program be madness, yet there is a method in't
aidan_walsh
aidan_walsh
Oh, right... Thanks guys... Guess I''ll be renaming them...

Cheers for the speedy responces!!


SketchSoft OFFLINE | SketchNews OFFLINE | NewKlear Studios

www.aidanwalsh(.net)(.info)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.