Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Mike Amling Newsgroups: comp.lang.java.programmer Subject: Re: How does it know? Date: Sun, 14 Sep 2014 08:52:55 -0500 Lines: 30 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net jNQH74/sj+4F2qlYBHYOJQiTIhO0A7piGfoiphTX0/q/pKo2zc Cancel-Lock: sha1:1dA/eLcq3+/T50outbq9LzyowOs= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:29975 On 9/12/14 6:18 PM, Knute Johnson wrote: > I'd like to figure out a way to store some sort of a reference to > Main.main() so that I could execute it. Any reason you don't want to use plain old reflection? import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; ... Method callme; try { callme=test1.class.getDeclaredMethod("main", new Class[]{new String[0].getClass()}); } catch (final NoSuchMethodException n) { return; } HashMap store=new HashMap(); store.put("main", callme); try { store.get("main").invoke(null, new Object[]{new String[0]}); } catch (final IllegalAccessException a) { } catch (final InvocationTargetException t) { } --Mike Amling Tm8gbmVlZCBmb3IgMS44LCBqdXN0IDEuMg==