One import static to rule them all
daniel.smith at oracle.com
Thu Feb 7 10:22:11 PST 2013
On Feb 6, 2013, at 5:35 PM, Remi Forax <forax at univ-mlv.fr> wrote:
> On 02/07/2013 01:28 AM, Kevin Bourrillion wrote:
>> I have been promised that this won't work -- that to invoke a static method on an interface one /must/ refer to the exact interface it was defined on, not a subtype, not an instance. Can someone please confirm this is true?
> We talk about a call like Interface.staticM(), but we never talk about the static import explicitly.
> So if someone does a static import on an interface, you suggest that the compiler should see only the static methods declared in the interface and all the static fields declared or inherited from inherited interfaces (for backward compat.) ?
The invocation restriction is imposed by defining inheritance such that the subinterface does not inherit its superinterface's members. So the parent's static methods are not members of the child. Static import, in turn, is defined in terms of the members of the child.
(In fact, the inability to invoke via a child isn't really the goal -- it's more like a side effect. The main goal, I think, is to avoid lots of pain points that arise we we start to deal with multiple inheritance of static methods.)
More information about the lambda-libs-spec-observers