Teen Programmers Unite  
 

 

Return to forum top

Reciprocating classes

Posted by boxcar [send private reply] at July 08, 2002, 11:45:00 AM

I have to update an applet which contains only 2 classes. The problem is that I can't compile either one. The first class requires the second class and the second class requires the first class. It looks something like:

public class first{
second objSecond
}

public class second{
first objFirst
}

I don't know how the person originally wrote it this way in the first place. Does anyone know of any works arounds without rewriting a bunch of the code? Any suggestions would be greatly appreciated. By the way, the language is Java.

Posted by Psion [send private reply] at July 08, 2002, 12:17:27 PM

I don't understand why this is a problem. You shouldn't need to do anything special to handle it.

Posted by boxcar [send private reply] at July 08, 2002, 12:24:55 PM

The problem is the first class won't compile because it is trying to use the second class which doesn't exist yet because it hasn't been compiled. When I try to compile the second class, it won't compile either because it needs the first class which also doesn't exist yet because it hasn't been compiled.

Posted by Psion [send private reply] at July 08, 2002, 12:30:54 PM

I don't think that is your problem. The latest javac handles the situation you describe perfectly. Perhaps your classpath environment variable is misconfigured and gives old versions of these classes priority.

Posted by gian [send private reply] at July 08, 2002, 03:53:02 PM

I'm not particularly familiar with Java, but could some prototype-like device not overcome this?

Posted by Psion [send private reply] at July 08, 2002, 06:05:40 PM

gian, not even that. It's all handled automatically. boxcar's problem definitely is with something else.

Posted by regretfuldaydreamer [send private reply] at July 08, 2002, 07:20:35 PM

Maybe if you put the two classes inside another class?

public class bigclass{

public class first{
second objSecond
}

public class second{
first objFirst
}
}

I'm not too sure if that would work, it's the best thing I can think of.

Posted by mrnorman [send private reply] at July 08, 2002, 07:49:07 PM

That would work fine under every version of java I've run.

Posted by taubz [send private reply] at July 08, 2002, 07:55:07 PM

And for the sake of information, there's no such thing as prototypes in java.

Posted by gian [send private reply] at July 08, 2002, 08:16:15 PM

Good to know!
Maybe I should start on the Java tutorial...

Posted by mrnorman [send private reply] at July 08, 2002, 08:22:27 PM

haha, I agree. I say it should all be defined at once anyway!

Posted by CodeRed [send private reply] at July 08, 2002, 09:32:36 PM

Prototyping would defeat the entire purpose of Java. And, as everyone has already said, boxcar's code should work just fine, maybe you have a really old version of java?

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.