Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92947 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78557 invoked from network); 29 Apr 2016 16:17:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2016 16:17:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=jesseschalken@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jesseschalken@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.173 as permitted sender) X-PHP-List-Original-Sender: jesseschalken@gmail.com X-Host-Fingerprint: 209.85.213.173 mail-ig0-f173.google.com Received: from [209.85.213.173] ([209.85.213.173:36240] helo=mail-ig0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 93/BF-26386-81983275 for ; Fri, 29 Apr 2016 12:17:29 -0400 Received: by mail-ig0-f173.google.com with SMTP id u10so27146133igr.1 for ; Fri, 29 Apr 2016 09:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc; bh=ATYhJj2FABpUJpmhztQBErsKbqoNDrdKlXwmn2m9ux4=; b=shatshSl5gOmB/yRdgxvwI7f4ph4hicdia4mJbS5j+2fuM39lQER5IwO8jcntJ3qpO eWK+O9lSMiRVOcV3A0prozuPjG1XCjHbDkJTbkNighkIYdnuMgavkmVIBLznMTdopogJ DjCbKPGTqjCk5E/Q1Nw7t71nHx3JU8wfPnhKavqHxxB7RI/4309OY7IPPaoqSXTQwM2d fGQCule7QqawSCdHYtTm+QCIbK59vzTBMYkb7S7RtGHOrDE7mHowo3+5umbwt6FYG1wi PYSZp+wPq3QWO76moM90CgFFoLxZt5OHDm/08HP1YJG+t61jvwy9SMVJToYZ7EbPiY/+ NBIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc; bh=ATYhJj2FABpUJpmhztQBErsKbqoNDrdKlXwmn2m9ux4=; b=hkyl0/v8vKiSV8X4k0Smw9Wvec6yLiKfAxC9t+Dp2vmgfdpBccgFe2au5RIomJRON0 C9YwUkumemYdE7NNUF2eUMQjjJdqPZpBrqn47ajD5wqSPq21npvWk4Rib/cv1JLblJEW CzrKfSQWNQIIw3o3O4RbjBtBLJpn8qnlNZp29efxsvzlBrIA47xJhalFCEo+KkFd/e+W Mz4ShQWSvd5RZAaiJdCeGilLmf/a1Eps6DwTFPXfjSG9DRSwFcfofMwFOuiRV15bOOcw j8YdIWhykdufmrLZqO95koN0yNZoSmdD+hlZhfqdiJzrGU7qYg15nLxU3z4djz0eToIR unxw== X-Gm-Message-State: AOPr4FVeO9weylXsET8Zv85lBsFna3ZxNywcMslOvFt1lzKlrFWVyNfg9lZwRHpfYvHjMyBwWAtEagpg+E3Q8Q== MIME-Version: 1.0 X-Received: by 10.50.72.107 with SMTP id c11mr5598843igv.85.1461946644490; Fri, 29 Apr 2016 09:17:24 -0700 (PDT) Sender: jesseschalken@gmail.com Received: by 10.79.139.133 with HTTP; Fri, 29 Apr 2016 09:17:24 -0700 (PDT) In-Reply-To: References: <3cc8a4c7-2640-11ae-a67b-06f909ac1e27@texthtml.net> <57173859.4080501@rochette.cc> <013101d19ff8$596b6010$0c422030$@tutteli.ch> Date: Sat, 30 Apr 2016 02:17:24 +1000 X-Google-Sender-Auth: XoQ3roKb1PRdqpTaLbYOlYo-m84 Message-ID: To: "guilhermeblanco@gmail.com" Cc: Robert Stoll , Rasmus Schultz , Josh Di Fabio , Dominic Grostate , Mathieu Rochette , "Ben Scholzen 'DASPRiD'" , Sara Golemon , PHP internals , Mathieu Rochette Content-Type: multipart/alternative; boundary=047d7bdc15ba6cf8df0531a1fa15 Subject: Re: [PHP-DEV] [RFC:generics] From: me@jesseschalken.com (Jesse Schalken) --047d7bdc15ba6cf8df0531a1fa15 Content-Type: text/plain; charset=UTF-8 On Sat, Apr 30, 2016 at 12:26 AM, guilhermeblanco@gmail.com < guilhermeblanco@gmail.com> wrote: > Wrong. This is documented here > https://docs.oracle.com/javase/tutorial/java/generics/upperBounded.html > and specifically states: > > To write the method that works on lists of Number and the subtypes of >> Number, such as Integer, Double, and Float, you would specify List> extends Number>. The term List is more restrictive than List> extends Number> because the former matches a list of type Number only, >> whereas the latter matches a list of type Number or any of its >> subclasses. > > > I think that documentation confirms what I wrote, but I guess it depends how you read it. In any case here is the corresponding Java code, with the output from javac for the lines that produce errors. You can test it yourself. package com.testvariance; import java.util.LinkedList; import java.util.List; class C { } class A extends C { } class B extends A { } public class Main { public static void main(String[] args) { // You can add subtypes of A to List in Java List la = new LinkedList(); la.add(new B()); // So if B extends A, List is compatible with List List lb = new LinkedList(); // when reading items you can assume they will be compatible with A (since B extends A) A a1 = lb.get(0); // but you can't add an A (because it's actually a list of Bs) lb.add(new A()); // Error:(25, 14) java: no suitable method found for add(com.testvariance.A) // So if A extends C, List is compatible with List List lc = new LinkedList(); // and you can add an A (because A is compatible with C) lc.add(new A()); // but when reading items you can't assume they're going to be As (because it's actually a list of Cs) A a2 = lc.get(0); // Error:(33, 28) java: incompatible types: capture#2 of ? super com.testvariance.A cannot be converted to com.testvariance.A } } > > Rasmus is purely following already defined PHP covariance definition that > currently exists for type hinting into generic types. > Wait, where does PHP already define covariance? The only type of generic I've ever seen in PHP is Foo[] generic array types in PhpDoc (which of course would be covariant because arrays are pass-by-value, unlike objects). AFAIK type hinting is presently restricted to plain classes/interfaces/scalars/array/callable, no generics at all. Java differs from that and accept covariance for type definitions, but > restricts for generic types. > > -- > Guilherme Blanco > Lead Architect at E-Block > --047d7bdc15ba6cf8df0531a1fa15--