i am having trouble with android-annotations and inheritance:
@EFragment(R.layout.fragment_foo)
public class TestBaseFragment {
@AfterViews
public void afterTestBaseFragmentViews() {
}
}
@EFragment(R.layout.fragment_foo)
public class TestFragment extends TestBaseFragment {
@AfterViews
public void afterTestFragmentViews() {
}
}
generates:
public final class TestFragment_
extends TestFragment
{
...
private void afterSetContentView_() {
afterTestFragmentViews();
afterTestBaseFragmentViews();
}
...
how can I make sure that afterTestBaseFragmentViews() is called before afterTestFragmentViews() ? Or can you point me to any document which describes how to do inheritance with AndroidAnnotations?
Annotations, just like methods or fields, can be inherited between class hierarchies. If an annotation declaration is marked with @Inherited , then a class that extends another class with this annotation can inherit it.
Annotations on methods are not inherited by default, so we need to handle this explicitly.
Inheritance allows the class to use the states and behavior of another class using extends keyword. Inheritance is-a relationship between a Base class and its child class.
Annotations allow you to provide hints to code inspections tools like Lint, to help detect these more subtle code problems. They are added as metadata tags that you attach to variables, parameters, and return values to inspect method return values, passed parameters, local variables, and fields.
It's just some sort of workaround
Using an abstract class:
@EFragment(R.layout.fragment_foo)
public abstract class TestBaseFragment {
@AfterViews
protected void afterTestBaseFragmentViews() {
// do something
afterView();
}
protected abstract void afterView();
}
@EFragment(R.layout.fragment_foo)
public class TestFragment extends TestBaseFragment {
@Override
protected void afterView() {
// do something after BaseFragment did something
}
}
Using simple subclassing:
@EFragment(R.layout.fragment_foo)
public class TestBaseFragment {
@AfterViews
protected void afterTestBaseFragmentViews() {
afterView();
}
public void afterView() {
// do something
}
}
@EFragment(R.layout.fragment_foo)
public class TestFragment extends TestBaseFragment {
@Override
public void afterView() {
super.afterView();
// do something after BaseFragment did something
}
}
I hope this is what you were looking for. (Not tested - just written in notepad)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With