Re: inheriting a main method
- From: Arne Vajhøj <arne@xxxxxxxxxx>
- Date: Mon, 14 Sep 2009 20:06:04 -0400
Andreas Leitgeb wrote:
Roedy Green <see_website@xxxxxxxxxxxxxxxxxxxx> wrote:I would like to write a base class from which child classes inherit aYou naturally inherit all static methods, including main.
public static void main( String args[] ) method.
You can specify which generation you want by prefixing the class name.
e.g. Grandma.main Mom.main Me.main
If there is no Me.main, you can use Me.main to get an Mom.main.
The real question was (as far as I understood it):
Can the implementation of Mom.main() find out, whether the user
used "Mom" or "Me" as startup class? Or perhaps even "Brother"
or "Sister", which for the sake of this example also do not have
their own main() but fall back to Mummy's?
I don't know any way, and I doubt there even is one, but can't say
for sure. Perhaps Java can be asked for the startup-class directly?
If we can assume that Java version >= 1.5, main thread has
thread id 1 and max. stack depth is 1000:
StackTraceElement[] ste = ManagementFactory.getThreadMXBean().getThreadInfo(1, 1000).getStackTrace();
String clznam = ste[ste.length-1].getClassName();
Arne
.
- Follow-Ups:
- Re: inheriting a main method
- From: Ross
- Re: inheriting a main method
- From: Mike Schilling
- Re: inheriting a main method
- References:
- inheriting a main method
- From: Ross
- Re: inheriting a main method
- From: Roedy Green
- Re: inheriting a main method
- From: Andreas Leitgeb
- inheriting a main method
- Prev by Date: Re: change your password day
- Next by Date: Re: inheriting a main method
- Previous by thread: Re: inheriting a main method
- Next by thread: Re: inheriting a main method
- Index(es):
Relevant Pages
|
Loading