I want to hide some methods within inheritable class from users.
For Example:
public class Test extends TextView {
public Test(Context context) {
super.onCreate(context);
}
/* hide this method */
@Override
protected void setText(CharSequence text) {
super.setText(text);
}
}
And then I don’t want to see this method within Test class.
How can I do it? Sorry for my English
This sounds like a design problem since hiding it seems a bit dirty as a base class assigned to subclass should still be able to call base class methods.
You could, however, do one of 2 things.
Mark the method as deprecated. Note: deprecated is usually used to tell people to not use the method b/c it will soon be removed but still presently works whereas here it would not work at all (presumably)…
AND throw UnsupportedOperationException in the method so that you / others catch it early if it is called.
Instead of subclassing consider composition. By this I mean make a class that wraps the desired class and expose only what you want. If you need a common interface between the original class and your wrapper class, create an interface that they both implement and use the interface but instantiate using your new class.