Paul Clapham wrote:And given this import:
it can be referred to as "Provider" in Java code. In your post you mentioned an import but didn't show us that import. Perhaps the study guide doesn't show it to you either? At any rate this one will do.
Your explanation that the
ServiceLoader.Provider<T> type may be referred to as the
Provider<T> type in Java code, when an appropriate import statement is used in such code, helps to clarify my second question. By the way, the study guide uses the following import:
The study guide informs that either this import or the one you gave (which is a static import) is okay for importing a static member into Java code (even though the study guide provides this information, I just found out that explicitly including the
static keyword in the
import statement is required if the imported static member is not a nested type, e.g., if the imported static member is a method; i.e., Java allows the omission of the
static keyword in the
import statement only when the imported static member is a nested type).
However, this explanation you provided doesn't assuage the non-clarity that underlies my first question, namely: Without the context that a
Provider<T> type is nested in the
ServiceLoader<T> type, it is confusing - as well as time-wasting to resolve this confusion - when a pedagogical text furnishes the signature for the
stream() method of the
ServiceLoader<T> class as in the point number 1, rather than the point number 2, below:
(1.)
Stream<Provider<S>> stream()
(2.)
Stream<ServiceLoader.Provider<S>> stream()
In fact, at
this page, the Java API furnishes the signature in point number 2, rather than the one in point number 1, above as the signature for the method. I just wonder how many people learning Java or even, in fact, actively using Java to write production code will be looking at the code that implements the core Java APIs, in order to apprise themselves of the various
import statements that various classes in these APIs employ to control namespaces in the code for the APIs?
Without the context that some piece of code uses an appropriate import statement in the code, in order to import the
Provider<T> type that is nested in the
ServiceLoader<T> type, furnishing the former type in a pedagogical text, as the return type of the
stream() method of the
ServiceLoader<T> class, is quite confusing as well as time-wasting indeed to people learning about this class and its methods.