Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35524
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Steven Simpson <ss@my.domain.invalid> |
| 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 | <skcj9d-c56.ln1@s.simpson148.btinternet.com> (permalink) |
| References | <df44fc1a-9d48-4ba8-890e-a687d24062a9@googlegroups.com> <cf527430-e940-4ba7-9579-096d1c80bd84@googlegroups.com> <npuiub$1a5i$1@gioia.aioe.org> <jd7b9d-imi.ln1@s.simpson148.btinternet.com> <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 |
Show key headers only | View raw
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<E> {
>>> public List<E> get();
>>> }
>>> public static <E> void checkToy(Toy<E> 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<F> { List<F> get(); }
static <E> void checkToy1(Toy<E> toy) { }
static void checkToy2(Toy<?> toy) { }
static List<Integer> 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
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Java 8 Lambda with generic types Stone Zhong <stone.zhong@gmail.com> - 2016-08-27 23:50 -0700
Re: Java 8 Lambda with generic types Stone Zhong <stone.zhong@gmail.com> - 2016-08-28 00:02 -0700
Re: Java 8 Lambda with generic types Arne Vajhøj <arne@vajhoej.dk> - 2016-08-28 07:46 -0400
Re: Java 8 Lambda with generic types Steven Simpson <ss@my.domain.invalid> - 2016-08-28 15:00 +0100
Re: Java 8 Lambda with generic types Lew <lewbloch@gmail.com> - 2016-08-30 22:25 -0700
Re: Java 8 Lambda with generic types Steven Simpson <ss@my.domain.invalid> - 2016-08-31 17:19 +0100
Re: Java 8 Lambda with generic types Steven Simpson <ss@my.domain.invalid> - 2016-08-28 08:19 +0100
Re: Java 8 Lambda with generic types Stone Zhong <stone.zhong@gmail.com> - 2016-08-28 03:26 -0700
Re: Java 8 Lambda with generic types Stone Zhong <stone.zhong@gmail.com> - 2016-08-28 07:45 -0700
Re: Java 8 Lambda with generic types Arne Vajhøj <arne@vajhoej.dk> - 2016-08-28 13:22 -0400
Re: Java 8 Lambda with generic types Stone Zhong <stone.zhong@gmail.com> - 2016-08-28 07:57 -0700
Re: Java 8 Lambda with generic types Stone Zhong <stone.zhong@gmail.com> - 2016-08-28 10:43 -0700
Re: Java 8 Lambda with generic types Arne Vajhøj <arne@vajhoej.dk> - 2016-08-30 20:35 -0400
Re: Java 8 Lambda with generic types Stone Zhong <stone.zhong@gmail.com> - 2016-09-02 15:18 -0700
csiph-web