Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is WaveItem class not abstract? #79

Closed
christophe-dooapp opened this issue Oct 7, 2013 · 6 comments
Closed

Why is WaveItem class not abstract? #79

christophe-dooapp opened this issue Oct 7, 2013 · 6 comments
Assignees
Labels
Milestone

Comments

@christophe-dooapp
Copy link

@christophe-dooapp christophe-dooapp commented Oct 7, 2013

I just create a new WaveItem by this code :

public static final WaveItem CONTAINER_KEY = new WaveItem("CONTAINER_KEY");

It throws me complicated ClassCastException, and I lost about 30min to understand that I need to override the WaveItem class by this code :

public static final WaveItem CONTAINER_KEY = new WaveItem("CONTAINER_KEY") {
};

As far as it's mandatory to use this class why don't make this class abstract?

@ghost ghost assigned sbordes Oct 7, 2013
@sbordes
Copy link
Member

@sbordes sbordes commented Oct 7, 2013

The WaveItem is used to hold a type that will be used as a method parameter, or within a WaveData wrapper.

So your code should be

public static final WaveItem CONTAINER_KEY = new WaveItem("CONTAINER_KEY") {
};

I will review your proposition for refactor it as Abstract class, there is another improvment I want to add related to attach a unique name dynamically (like the enum name() does, but I didn't find the most stylish way)

@christophe-dooapp
Copy link
Author

@christophe-dooapp christophe-dooapp commented Oct 7, 2013

In fact, I based my request on Google Guice TypeLiteral. (It use the same system as yours to handle generics)

http://google-guice.googlecode.com/git/javadoc/com/google/inject/TypeLiteral.html

@sbordes
Copy link
Member

@sbordes sbordes commented Oct 7, 2013

But TypeLiteral is not an abstract class ?

What do you think if I write this warning into the (wip) documentation ?

Don't forget the {} for WaveItems !

I could change the default constructor visibility like they do

protected TypeLiteral() {...}

It will have a lower impact thantdeclaring the class abstract.

I will pushed it tonight on 0.7.6-SNAPSHOT version

@sbordes sbordes closed this in 1fe7aa8 Oct 7, 2013
@christophe-dooapp
Copy link
Author

@christophe-dooapp christophe-dooapp commented Oct 8, 2013

Tank you.

For me, abstract class or protected constructor are the same when you use it.

@sbordes
Copy link
Member

@sbordes sbordes commented Oct 8, 2013

But 'conceptually' an abstract class requires at least one abstract method.
Protected constructors fit perfectly the need

Thanks for the feedback, I still have to greatly improve documentation, don't hesitate to contact me for any question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.