Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: getting generic type parameter in method Date: Wed, 21 Oct 2020 08:43:06 -0400 Organization: A noiseless patient Spider Lines: 23 Message-ID: References: <7e2c11ae-85bd-42cd-a7a7-27313edb9178n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 21 Oct 2020 12:43:09 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="6895006881a8baa16a6b4a7db70f0207"; logging-data="19317"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bZFfvbwT5y/SjI0MiTEcV" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.3.3 Cancel-Lock: sha1:aiLo614ymsfELUlBXUcYyy4xy2o= In-Reply-To: <7e2c11ae-85bd-42cd-a7a7-27313edb9178n@googlegroups.com> Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:39629 On 10/21/2020 7:38 AM, Philipp Kraus wrote: > Hello, > > I'm implementing an interface of a library, which I can use for deserialization a byte array into my own datastructures. The method is: > > public T fromData( @Nonnull final byte[] p_bytes, @Nonnull final Class p_class, @Nonnull final Type p_type ) throws DataConverterException > [...] > I have taken a look into Google Guava and Apache Commons with the ReflectUtils / TypeUtils, but I don't know How I get get from my p_class Variable the details auf T during runtime. I'm not up to speed on all the latest developments, but I think you're out of luck at least through Java 15. JLS 4.7 describes which types are "reifiable," and includes a discussion on why some types (including most generic types) are not. Perhaps in some future Java things will change, but I don't believe they've changed yet. (However, "perhaps" I'm wrong. I'm at Java 11 these days, and have not fully explored the more recent releases.) -- esosman@comcast-dot-net.invalid "Total honesty is what we as citizens deserve from our president." -- Melania Trump Ninety-one days to go.