Answer the question
In order to leave comments, you need to log in
How to hide a Java class method?
Actually, how to hide / make some class methods not available?
For example, overwritten public methods of the parent class:
public class MyLayout extends FrameLayout {
public MyLayout(Context context) {
super(context);
}
/**
* КАК СДЕЛАТЬ ЭТОТ МЕТОД НЕДОСТУПНЫМ / ИЗМЕНИТЬ ВИДИМОСТЬ ???
*/
@Override
public void addView(View child) {
super.addView(child);
}
}
//Вот это
public override string ToString() {}
//Меняли на это
private new string ToString() {}
/** @hide */
public boolean isAutofillCompatibilityEnabled() {
return false;
}
Answer the question
In order to leave comments, you need to log in
Within Java, you cannot change the visibility of an inherited method. There are several options. First, you can leave the method override empty and move the functionality to another place. Second, to do it right, you need extra encapsulation, so use the tools of the language, create an interface that offers only the necessary methods.
Annotations in comments, inside the Android API, have a different meaning. For example, it @hide
says that the method was not designed to be used outside of the API.
As a last resort, you can just make it empty. That is, with an empty body.
I would like to add that in java it is still possible to change the visibility of an inherited method, but only towards the extension. It is really impossible to narrow down - this would be a violation of the principle of Barbara Liskov.
And the tags in the comments are javadoc markup. And such comments are not comments at all, but documentation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question