[cdi-dev] [JBoss JIRA] Commented: (CDI-127) Add support for annotation scanning of Java enums

Pete Muir (JIRA) jira-events at lists.jboss.org
Tue Jun 21 09:10:23 EDT 2011

    [ https://issues.jboss.org/browse/CDI-127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12610065#comment-12610065 ] 

Pete Muir commented on CDI-127:

h1. Notes

Enums are somewhat different to normal classes, as Java guarantees that any instances are singletons. Therefore we cannot treat them as classes. Furthermore, do we want to support them as beans, allowing them to be injected?

Differences are:

* No callback on instantiation, when do we inject?
* Shared between deployments as singletons, how do we handle dependent scoped injections?
* We do not control instantiation, cannot perform constructor injection

h1. Proposal

We should support enums as non-contextual objects, performing field injection only. Enums should be assumed to be injected only after the application is fully initialized for portability.

If an enum is on a shared classloader, any injections should correctly resolve to the deployment of the calling context. In other words, if a shared library or installed library has an enum A:

enum A {

   FOO, BAR;

   @Inject B b;

   String getName() {
      return b.name;


where B is a class defined in the shared library

class B {

   String name;


Then assuming that the name has been set to Pete in deployment 1, and Marius in deployment 2, when the enum A is used in deployment 1, the method getName() should return Pete, and in deployment 2 it should return Marius.

> Add support for annotation scanning of Java enums
> -------------------------------------------------
>                 Key: CDI-127
>                 URL: https://issues.jboss.org/browse/CDI-127
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Beans
>            Reporter: Brian Leathem
>             Fix For: 1.1 (Proposed)
> It would be useful if Java enums were included in the CDI annotation scan.
> A use case for this is found in the Seam Faces project, where we would like to use annotations on enums for configuration purposes.  The annotation would look like:
> @ViewConfig
> public enum Pages {
>     ...
> }
> It is my understanding that the current CDI specification (1.0) does not require scanning of the enum and will not pick up the @ViewConfig annotation.

This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the cdi-dev mailing list