Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35524
| From | Steven Simpson <ss@my.domain.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java 8 Lambda with generic types |
| Date | 2016-08-31 17:19 +0100 |
| Organization | A noiseless patient Spider |
| 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> |
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