Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

You can check if the returned object is a nullable object with the test: "myservice instanceof Nullable".

You can disable the Nullable pattern too (activated by default). In this case, iPOJO will inject null instead of a Nullable object. So, you can just test if your field is equals to null to check if the service is available. To disable the Nullable pattern, you need to add the 'nullable="false"' attribute in your service dependency description as follows:

Code Block
xml
xml

<component classname="...LogExample">
    <requires field="m_log" optional="true" nullable="false"/>
    ...
</component>

However, you can also indicate a default-implementation for your optional service. In this case, if no providers are found, iPOJO creates an instance of the default-implementation and injects it. The default-implementation attribute describes the class name of your implementation. The given class MUSTimplement the required service interface.

...