[ 
http://issues.apache.org/jira/browse/LANG-76?page=comments#action_12444477 ] 
            
Henri Yandell commented on LANG-76:
-----------------------------------

Apologies for how long it's taken to get around to this issue - largely because 
it doesn't seem like an issue with much of a solution. Even if the RFE is 
solved (and it looks like it might be someday), I suspect it's unlikely it 
would be backported to Java 5.0.

If I'm understanding things correctly, the problem is that in 1.4 Igor had code 
that just said IgorEnum.class. This initialised all the constant enum 
declarations within his IgorEnum class - which I presume was necessary for some 
reason (ie: he couldn't just say 'IgorEnum.ONE' and have it work). 

The work-around would appear to be to create a static enumInitialize() method 
within the IgorEnum class that looks much like this:

    static void enumInitialize() {
        TT tmp = ONE;    // or whatever kind of setup call is needed
    }

Then change the 'Class tmp = IgorEnum.class' to 'IgorEnum.enumInitialize()'. 

I suspect I'm missing something in the complexity behind why the IgorEnum.class 
call was desirable in the first place.

> [lang] EnumUtils.getEnum() doesn't work well in 1.5
> ---------------------------------------------------
>
>                 Key: LANG-76
>                 URL: http://issues.apache.org/jira/browse/LANG-76
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.1
>         Environment: Operating System: other
> Platform: Other
>            Reporter: Igor Laberov
>             Fix For: 2.3
>
>
> Hi,
> I encountered with problem using EnumUtils.getEnum() in 1.5. It appears that 
> my
> Enum class should be accessed first so constructor will be called. In 1.4 it 
> was
> enough to have myClass.class, so all static members were initialized. In 1.5 
> it
> doesn't work.
> I noticed that static members are not initialized anymore while acessing to
> class definition. See the code
> public class Test {
>     public static final class TT{
>         public static final TT one = new TT();
>         private TT(){
>             System.out.println("Called TT" );
>         }
>     }
>     
>     public static void main(String[] args) {
>      Class cl = TT.class;
>    // System.out.println( TT.one);
>   //  System.out.println(TT.class.isAssignableFrom(String.class));
>     }
> }
> In 1.4 constructor of TT is called, while in 1.5 is not. 
> Actually, according to the spec
> (http://java.sun.com/docs/books/jls/second_edition/html/execution.doc.html#57946),
> this is right behavior of Java. 
> Unfortunately, I didn't succeded to think about good solution..
> P.s. I know that in 1.5 we have enum built-in, but it is not the same, and we
> try to move to 1.5 without too much changes

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to