Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #11418
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe10.iad.POSTED!83aa503d!not-for-mail |
|---|---|
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: enum paralellism |
| References | <4tb8h7h2tul5rq4m5bk9sg485tq33qi394@4ax.com> |
| In-Reply-To | <4tb8h7h2tul5rq4m5bk9sg485tq33qi394@4ax.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Lines | 30 |
| Message-ID | <kbjRq.962$744.661@newsfe10.iad> (permalink) |
| X-Complaints-To | abuse@newsrazor.net |
| NNTP-Posting-Date | Tue, 17 Jan 2012 18:34:56 UTC |
| Date | Tue, 17 Jan 2012 10:34:55 -0800 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11418 |
Show key headers only | View raw
On 1/16/12 6:16 AM, Roedy Green wrote:
> What if you have two enum classes that have similar structure, e.g.
> similar method names, similar instance variables or similar enum
> constants.
>
> Is there any way to specify that similarity in one place or to use
> interfaces, abstract classes, EnumSets or inheritance to enforce the
> parallel structure? I have not found a way.
Enums can implement interfaces:
public enum MyEnum implements Runnable {
A { public void run() { System.out.println("A Runs!"); } },
B { public void run() { System.out.println("B is an also ran."); } }
;
}
But they can not extend other classes. Enum *constants* however
automatically extend the (automatically abstract) Enum class. So you can
have abstract methods in the base enum class.
public enum MyEnum {
A { public void run() { System.out.println("A Runs!"); } },
B { public void run() { System.out.println("B is an also ran."); } }
;
public abstract void run();
}
It sounds like you want a combination of abstract methods and interfaces.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
enum paralellism Roedy Green <see_website@mindprod.com.invalid> - 2012-01-16 06:16 -0800
Re: enum paralellism Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-01-16 10:33 -0500
[OT] East and West in Oz (Was: enum paralellism) Lew <noone@lewscanon.com> - 2012-01-16 10:32 -0800
Re: enum paralellism Roedy Green <see_website@mindprod.com.invalid> - 2012-01-17 10:08 -0800
Re: enum paralellism Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-01-17 10:37 -0800
Re: enum paralellism Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-01-17 10:34 -0800
csiph-web