"Provides" and "with" type relationships

Alex Buckley alex.buckley at oracle.com
Tue Mar 15 19:26:15 UTC 2016


The first operand to 'provides' (the "service interface") is not 
constrained to be an interface by "Modules in the Java Language and 
JVM". This is because the spec of j.u.ServiceLoader ("a service is 
represented by a single type, that is, a single interface or abstract 
class").

The second operand to 'provides' (the "service implementation") is 
constrained not to be an interface or an abstract class by "Modules in 
the Java Language and JVM". This is also because of the spec of 
j.u.ServiceLoader ("provider classes must have a zero-argument 
constructor so that they can be instantiated during loading").

Bear in mind that the JCK team can easily set up abstract test cases 
like this. What they can't do is check whether YOUR application runs on 
JDK-9-with-Jigsaw, or whether arbitrary JARs on YOUR classpath work as 
automatic modules.

Alex

On 3/15/2016 12:07 PM, Paul Benedict wrote:
> module z {
>      exports z;
>      provides z.Main with z.Main;
> }
>
> The SOTM says "Service-provider declarations can be further interpreted to
> ensure that providers (e.g., com.mysql.jdbc.Driver) actually do implement
> their declared service interfaces" (section 4, para. 8).
>
> I see javac checking that they are related types, but javac is not checking
> that "provides" is an interface type. That is what I was expecting based on
> the reading material.
>
> The other unexpected outcome was that provides/with allows the identical
> type. I don't know if that's intended, but please advise.
>
> PS: I did go through the open tickets this time (thanks Alan) and do not
> see any similar reports. If I missed it, I apologize; just trying not to
> waste your time by reporting a duplicate.
>
> Cheers,
> Paul
>


More information about the jigsaw-dev mailing list