The spec currently does not require the auto-closeable beans to implement the AutoCloseable interface, i.e. an auto-closeable bean is not required to define AutoCloseable in its set of bean types.
So a user can annotate any bean with @AutoClose but it's a NOOP unless it implements AutoCloseable.
Since @AutoClose makes no sense without AutoCloseable, it might be worth tightening the requirements and treat @AutoClose without AutoCloseable as a definition error. This could help users understand the purpose of the annotation.
I know that one argument against this requirement is more flexibility in producer methods:
@Produces
@AutoClose
public FooBar produce() {
// FooBar is not AutoClosable -> NOOP is expected
return someCondition ? new FooBar() : new CloseableFooBar();
}
But I'm not sure this flexibility is worth it. And it definitely makes no sense for class-based beans.
The spec currently does not require the auto-closeable beans to implement the
AutoCloseableinterface, i.e. an auto-closeable bean is not required to defineAutoCloseablein its set of bean types.So a user can annotate any bean with
@AutoClosebut it's a NOOP unless it implementsAutoCloseable.Since
@AutoClosemakes no sense withoutAutoCloseable, it might be worth tightening the requirements and treat@AutoClosewithoutAutoCloseableas a definition error. This could help users understand the purpose of the annotation.I know that one argument against this requirement is more flexibility in producer methods:
But I'm not sure this flexibility is worth it. And it definitely makes no sense for class-based beans.