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

Fix ArgsBundler return type #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface ArgsBundler<T> {
* @param bundle The Bundle where the value is saved in
* @return The value retrieved from the Bundle with the given key
*/
public <V extends T> V get(String key, Bundle bundle);
public T get(String key, Bundle bundle);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ParcelerArgsBundler implements ArgsBundler<Object> {
bundle.putParcelable(key, Parcels.wrap(value));
}

@Override public <V> V get(String key, Bundle bundle) {
@Override public Object get(String key, Bundle bundle) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that this is working properly? I mean, if we return here Object somewhere has to be a cast to the real class, right? By using generic methods <V> the compiler can determine what the actual return type is because Parcels.unwrap() knows <V> too.

Copy link
Author

@vganin vganin Jul 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I've assembled test project and I see the problem now. I've updated the PR.

My proposition is to remove inferred return type from interface and add strict casting to generated code. Pros are obvious but there is one caveat. User can specify the inheritor of arg class and try to use the bundler for its super class. In this case we get ClassCastException in run time instead of compile time error. Although I don't think somebody will do something like that (only mistakenely maybe).

return Parcels.unwrap(bundle.getParcelable(key));
}
}