"Provides" and "with" type relationships

Alex Buckley alex.buckley at oracle.com
Tue Mar 15 20:14:34 UTC 2016


A 'provides' clause specifies two things: a service interface and a 
service implementation. Using those terms helps to avoid confusion. A 
service interface does not have to be an interface; it can be an 
abstract class or even (not recommended) a concrete class. A service 
implementation must not be an interface, or an abstract class; it must 
be a concrete class. Therefore, it's not OK if the same type is 
specified as both service interface and service implementation, and JCK 
will be writing tests for that, I promise.

Alex

On 3/15/2016 12:39 PM, Paul Benedict wrote:
> Thanks for your response Alex. If I am understanding you correctly,
> "provides" is "not constrained to be an interface" because it can be "a
> single interface or abstract class". So shouldn't my concrete class for
> "provides" be rejected by the compiler? And is it okay that both types
> were identical?
>
> Cheers,
> Paul
>
> On Tue, Mar 15, 2016 at 2:26 PM, Alex Buckley <alex.buckley at oracle.com
> <mailto:alex.buckley at oracle.com>> wrote:
>
>     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