-
Notifications
You must be signed in to change notification settings - Fork 87
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
Warning when implementing ArgsBundler #53
Comments
What exactly do you mean? This warning should be supressed by the library. Regarding the type For instance to write a custom ArgsBundler for types of Date you have to implement something like this: public class DateArgsBundler implements ArgsBundler<Date>{
@Override public void put(String key, Date value, Bundle bundle) {
bundle.putLong(key, value.getTime());
}
@Override public Date get(String key, Bundle bundle) {
long timestamp = bundle.getLong(key);
return new Date(timestamp);
}
}
public class MyFragment extends Fragment {
@Arg ( bundler = DateArgsBundler.class )
Date date;
} |
The way how to implement custom ArgsBundler is clear. I just want to pointed out that when using Android Studio auto generating for interface implementation we will have : public class DateArgsBundler implements ArgsBundler<Date> {
@Override
public void put(String key, Date value, Bundle bundle) {
}
@Override
public <V extends T> V get(String key, Bundle bundle) {
return null;
}
} Which is obviously incorrect. When we fix method get like this @Override
public Date get(String key, Bundle bundle) {
return null;
} We will have Unchecked overriding warning. This happens because the return type of get method in parametrized interface So we need to suppress it with Maybe this is reasonable approach, but I cant understand the reason. Can you please explain it? |
Ah, now I understand what you mean. The reason was Parceler and other libraries that are working in a similar fashion. But lets stick with Parceler. The problem with parceler is that the api public static <T> T unwrap(Parcelable input); The problem is that those methods from Parceler have generic type methods parameters and that java generics are not strong enough to detect a safe cast somehow: fragment.foo = fooBunder.get(key, bundle); Where foo is some class If you know a better way, don't hesitate to prove me wrong an I will change that ... |
When I am copying implementation of any ArgsBundler from sources, for example NoneArgsBundler, Android Studio warns me about unchecked method overriding. Is it a bug or my misunderstanding? What is the reason of using this generic in interface: ? Why we should can't use T generic type instead?
The text was updated successfully, but these errors were encountered: