Path: csiph.com!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Java 8 Lambda with generic types Date: Sun, 28 Aug 2016 13:22:43 -0400 Organization: Aioe.org NNTP Server Lines: 37 Message-ID: References: <9ff6ad3e-bb82-4207-91d8-f03c707a1dcf@googlegroups.com> NNTP-Posting-Host: 7SK6yTFfqwlIPNBLl3l7Qg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; 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.2.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:35490 On 8/28/2016 10:45 AM, Stone Zhong wrote: > Having checkToy take generic parameter is a workaround, but it does not solve the problem which it does not work with . For example, if you have: > > > public static void checkToys(Toy ... toys) { > } > > You cannot put a generic type here for checkToys, and you cannot call > > checkToys( > () -> Arrays.asList(10), > () -> Arrays.asList("hello") > ); > > But you can do > > checkToys( > new Toy() { > @Override > public List get() { > return Arrays.asList(1, 2, 3); > } > }, > new Toy() { > @Override > public List get() { > return Arrays.asList("a", "b", "c"); > } > } > ); @SuppressWarnings("rawtypes") public static void checkToys(Toy ... toys) { Arne