Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Steven Simpson Newsgroups: comp.lang.java.programmer Subject: Re: Java 8 Lambda with generic types Date: Wed, 31 Aug 2016 17:19:08 +0100 Organization: A noiseless patient Spider Lines: 33 Message-ID: References: <74d17a27-7891-4de2-963d-387108bb6874@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="2616e54f6b880240e435d1d4d81efe54"; logging-data="14329"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xWP3oO8TuypFpEMOAvBRlFVj2cjo56hs=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: <74d17a27-7891-4de2-963d-387108bb6874@googlegroups.com> Cancel-Lock: sha1:E/6ChKKvzV5vCW5/yeAgQKcxoSw= Xref: csiph.com comp.lang.java.programmer:35524 On 31/08/16 06:25, Lew wrote: > On Sunday, August 28, 2016 at 7:15:11 AM UTC-7, Steven Simpson wrote: >> On 28/08/16 12:46, Arne Vajhøj wrote: >>> public class GenFun { >>> public static interface Toy { >>> public List get(); >>> } >>> public static void checkToy(Toy toy) { >> I found that worked too, but what is the difference between that and >> , when E is only referenced once? > When you use a wildcard in lieu of the generic type parameter, you are losing the information that the type in the is the same as `E`. There is no way for the compiler to know that the type of the `Toy toy` argument is compatible with `E`. It's possible I've conflated Arne's portion of the discussion with my own (my mistake), so I'm not sure which E you're referring to. I mean, if we have: interface Toy { List get(); } static void checkToy1(Toy toy) { } static void checkToy2(Toy toy) { } static List makeList() { ... } ...why does the compiler accept checkToy1(() -> makeList()), but not checkToy2(() -> makeList())? Is there a simpler case to demonstrate the distinction? Is there one without lambdas/method references? -- ss at comp dot lancs dot ac dot uk