Re: Generic classes and methods RFC
| From: | Korvin Szanto | Date: | Fri, 11 Sep 2015 16:00:07 +0000 |
| Subject: | Re: Generic classes and methods RFC | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88155@lists.php.net to get a copy of this message | ||
Levi,
It's my understanding that the "type variable" is a member of the instance
and not of the class. In at least java, generics are unavailable in static
context[1] though they can be specifically defined on the static method
itself[2].
[1]
http://stackoverflow.com/questions/936377/static-method-in-a-generic-class
[2] https://docs.oracle.com/javase/tutorial/extra/generics/methods.html
On Fri, Sep 11, 2015 at 8:28 AM Levi Morrison <levim@php.net> wrote:
> On Thu, Sep 10, 2015 at 5:12 PM, Ben Scholzen 'DASPRiD'
> <mail@dasprids.de> wrote:
> > Hi Dennis,
> >
> > thanks for your feedback, see my answers below:
> >
> >> 1. static methods:
> >>
> >> class Foo<T> {
> >> public static function test() {
> >> }
> >> }
> >>
> >> how can I call the method:
> >> a) Foo::test()
> >> or
> >> b) Foo<int>::test()
> >>
> >> in case b), would the generic methods not be a duplication?
> >
> >
> > Case a) is correct here. A static method is not in the context of an
> > instance, so it doesn't know about the class boxing by itself.
>
> I think b would be correct. Can you explain this rationale a bit more?
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>