General Java Questions I
I hope the next versions of Java explores this issue.
Answer: It does. They re called interfaces:
interface A { public void setX(); public void setY(); public void setAll(); }
interface B { public void setC(); public void setD(); public void setBoth(); }
interface C extends A,B {};
public abstract class D implements C {
}
jim
Is there a way to know from class X which class called the method foo()?
If class A and class B are calling a method foo() on class X, is there a way to know
from class X which class called the method foo() (they can be either A or B). I know
that this can be done by capturing the stack trace and examining it, but that solution
looks expensive as I have to create a new Throwable object every time and capture
stack trace (And I do this quite frequently).
Is there any other elegant solution to do this, any help and direction
is appreciated.
Answer: Pass a reference to the class to the foo() method.
foo(Object x){
System.out.println(x.getClass());
}
should do it.
Why does this simple application never exit?
public class UIQuitTest {
public static void main (String[] args) {
java.awt.Frame f = new java.awt.Frame();
f.dispose();
f = null;
} // end of main ()
}
The application above never quits, is it a bug or a (mis)feature? Win98, JRE 1.3.0
Answer: By creating an AWT object, you now have started the AWT thread. In order
to end the application now, you have to do a System.exit(0) that will kill all
non daemon threads, including the AWT thread.
Q: Is it possible to stop an object from being created during construction?
For example if an error occurs inside the constructor (e.g. the parameters pass in
were invalid) and I wanted to stop an object being created would it be possible to
return null rather than a reference to a new object. (I know the term return is
technically correct in this case but you know what I mean).
Basically, is it possible to cancel object creation?
file:///F|/a_jsite/350_tips/general_java I.htm (17 of 33) [2001 07 08 11:24:51]
footer
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved