Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?Q?Joshua_Cranmer_=f0=9f=90=a7?= Newsgroups: comp.lang.java.programmer Subject: Re: Generic cannot be applied Date: Thu, 26 Nov 2015 11:06:54 -0600 Organization: A noiseless patient Spider Lines: 29 Message-ID: References: <46618f03-00af-47fe-affa-5e12b9a2f4cc@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 26 Nov 2015 17:04:35 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="fd083e583875d719dcabb768f03a1877"; logging-data="30614"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jsHi0BwWp3GRQyZYxPp6zjwi6MNz2dAs=" User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:42.0) Gecko/20100101 Thunderbird/42.0 In-Reply-To: <46618f03-00af-47fe-affa-5e12b9a2f4cc@googlegroups.com> Cancel-Lock: sha1:26g4XBz2EFKNWrw36S512LJdeyI= Xref: csiph.com comp.lang.java.programmer:33208 On 11/25/2015 3:33 PM, Philipp Kraus wrote: > public class myOperator implements Operator > { > public IVariable evaluate( IVariable p ) > { > p.set( new Double(p.get().doubleValue() + 1) ); <<< The generic types don't mean what you think they mean. It's perhaps easiest to understand the generic type subtyping relationships by illustrating how they work on a basic container type, e.g., List. A List naturally stores objects of only type T. So if you have List, you can add Number objects to the list and you can get Number objects from the list. However, if you change to List, what you're saying is that "This is a list of something. That something must be a subtype of Number." Thus, objects of type List can't *store* anything (since you don't know what type it's storing), but you can read from the list. In contrast, there is another type bound you can specify. List means "This is a list of something which is a superclass of Number"--so you can store Numbers in it, but you can't read anything from it (except as Objects). -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth