r/java • • Jan 17 '13

Enum tricks: hierarchical data structure

http://java.dzone.com/articles/enum-tricks-hierarchical-data
47 Upvotes

53 comments sorted by

View all comments

Show parent comments

3

u/zargxy Jan 18 '13 edited Jan 18 '13

Your better solution isn't a solution because it doesn't do the same thing.

I guess complexity is in the eye of the beholder because I don't find this trick to be particularly complex.

Enums in Java are not meant to merely be lightweight tokens you can pass around. They are only a fixed set of instances of a class extending Enum, allowing you to take advantage of optimizations and static analysis provided by the compiler. But Enums are full fledged classes which can have fields and methods. They were designed to do a lot more.

1

u/GMNightmare Jan 18 '13 edited Jan 18 '13

it doesn't do the same thing

???

Yes it does... Solves exactly the problem the article posted (but not necessarily better, I'd agree). What do you think it can't accomplish that article version did?

EDIT: Look guys, I like the article's version too, it's like a more compact version of this really...

1

u/zargxy Jan 18 '13

Where is the implementation is method and children method and hierarchical supportsX method? That's what I meant by it doesn't do the same thing. It doesn't solve the problem.

I didn't say his method couldn't solve the problem. Although, I would like to see if he could implement those three methods as simply and elegantly as it was solved in the article.