Can I add and remove elements of enumeration at runtime in Java
        Posted  
        
            by Brabster
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Brabster
        
        
        
        Published on 2009-01-25T22:08:54Z
        Indexed on 
            2010/03/15
            11:59 UTC
        
        
        Read the original article
        Hit count: 258
        
It is possible to add and remove elements from an enum in Java at runtime?
For example, could I read in the labels and constructor arguments of an enum from a file?
@saua, it's just a question of whether it can be done out of interest really. I was hoping there'd be some neat way of altering the running bytecode, maybe using BCEL or something. I've also followed up with this question because I realised I wasn't totally sure when an enum should be used.
I'm pretty convinced that the right answer would be to use a collection that ensured uniqueness instead of an enum if I want to be able to alter the contents safely at runtime.
© Stack Overflow or respective owner