Skip to main content



      Home
Home » Newcomers » Newcomers » Howto "extend" enumerations
Howto "extend" enumerations [message #145472] Wed, 29 March 2006 09:06
Eclipse UserFriend
Hi!

A couple of times lately I have found myself needing to "extend"
enumerations.
I know that this is not doable explicitly, but is there a "way around" such
as a nice pattern or likewise.

Example:

I have an interface A that defines an enumeration SomeEnumeration, i.e.

public interface A
{
public enum SomeEnum
{
SE1,
SE2,
SE3;
}
}

In implementing classes, e.g. B I would like to extend this enumeration so
that:

public class B implements A
{
public enum SomeEnumB extends SomeEnum
{
SE1 (1),
SE2 (2),
SE3 (3);

int value;

private SomeEnumB(int value) {this.value = value;}
public int getValue() {return this.value;}
}
}


But it does not work since I can't extend the enumeration SomeEnum.

As I mentioned I have many occasions where this would have come in very
handy.
I want the safety of an enumeration, but also the possibility to add
functionality.

For example imagine that SomeEnum had an abstract method
(SomeEnumImpl.process(DataSource ds)) than extending enumerations implement.
The implementation could e.g. depend on the underlying datasource or
similar.

I hope that someone is getting what I am getting at.

Regards,
Jimisola
Previous Topic:Java Editor Puts Certain Things In Italics
Next Topic:How to keep java windows from popping up
Goto Forum:
  


Current Time: Sat Jun 07 00:24:34 EDT 2025

Powered by FUDForum. Page generated in 0.07358 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top