Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34207
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: type question |
| Date | 2016-04-26 19:32 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <nfotqh$hth$1@gioia.aioe.org> (permalink) |
| References | <0b41efc4-f925-466b-ae42-76f484c50bc9@googlegroups.com> |
On 4/26/2016 2:04 PM, mcheung63@gmail.com wrote:
> This line works:
>
> new Gson().fromJson(httpResult.content, new TypeToken<ArrayList<StockBalance>>() {
>
>
> Now i want to create a function with a parameter for the last one, and i failed
>
>
> function1(new ArrayList<StockBalance>().getClass());
>
> public static <T> T function1(Class<T> clazz) {
> return new Gson().fromJson(httpResult.content, new TypeToken<ArrayList<StockBalance>>() {}.getType());
> }
>
>
> !!! the last parameter is wrong, able to compile but can't work.
You did not specify compile error message or provide enough
code so that we can compile.
But The function is declared to return T but fromJson return
blabla.getType() which is not necessarily T.
That looks very funky.
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
type question mcheung63@gmail.com - 2016-04-26 11:04 -0700 Re: type question Arne Vajhøj <arne@vajhoej.dk> - 2016-04-26 19:32 -0400
csiph-web