Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34207

Re: type question

Path csiph.com!aioe.org!.POSTED!not-for-mail
From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: type question
Date Tue, 26 Apr 2016 19:32:35 -0400
Organization Aioe.org NNTP Server
Lines 28
Message-ID <nfotqh$hth$1@gioia.aioe.org> (permalink)
References <0b41efc4-f925-466b-ae42-76f484c50bc9@googlegroups.com>
NNTP-Posting-Host ANasIS7Js9OyLQwgloeBLQ.user.gioia.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.java.programmer:34207

Show key headers only | View raw


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


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