Date: Wed, 07 Sep 2011 17:25:52 +0200 From: John User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Define Type at runtime References: <4e678737$1@news.x-privat.org> <4e678ab5$0$13073$426a74cc@news.free.fr> In-Reply-To: <4e678ab5$0$13073$426a74cc@news.free.fr> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: $$afwhll$slnyo.news.x-privat.org Message-ID: <4e678d02$2@news.x-privat.org> Organization: X-Privat.Org NNTP Server - http://www.x-privat.org Lines: 20 X-Authenticated-User: $$p9zou1n1$ng5dhdq$s2 X-Complaints-To: abuse@x-privat.org Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!newsfeed.x-privat.org!x-privat.org!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7683 Il 07/09/2011 17:20, Mayeul ha scritto: > On 07/09/2011 17:01, John wrote: >> If I have a method: >> public void someMethod(Object o){ >> ... >> Entity entity; >> .... >> } >> >> How could I define at runtime the type T if I have an Object? > > You can't. Generics are a compile-time-only tool. They are erased at > runtime. > > You need to organize your program so that type-safety is checked > entirely at compile-time. Or, if impractical, to just renounce > type-safety and work with something like Entity instead. Ok, solved. Thank you