I can't believe I didn't find anything here for this Question, so:
Why do I need to explicitly define all Constructors of a superclass when deriving a class. Why does Java not automatically call the super constructor, when the derived class doesn't offer one with that signature.
That would be some nice piece of "Syntactic Sugar".
E.g: In Android each View Subclass offers 3 Constructors that are called either from XML or from Code. To be able to create a custom View in Code and in XML I need to define all three constructors, even if they don't do anything. Here is a small example I had to write yesterday
public class OverfocusableGridView extends GridView {
public OverfocusableGridView(Context context) {
super(context);
}
public OverfocusableGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public OverfocusableGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean keyHandled = false;
if (this.getSelectedView() != null) {
int focusedViewPosition = this.getSelectedItemPosition();
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
if (focusedViewPosition > 0) {
int prevItemPosition = focusedViewPosition - 1;
this.setSelection(prevItemPosition);
keyHandled = true;
}
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (focusedViewPosition < this.getChildCount() - 1) {
int nextItemPosition = focusedViewPosition + 1;
this.setSelection(nextItemPosition);
keyHandled = true;
}
break;
default:
keyHandled = super.onKeyDown(keyCode, event);
}
} else {
keyHandled = super.onKeyDown(keyCode, event);
}
return keyHandled;
}
}
Would be much nicer if I would not need to define theese Constructors. Are there any downsides with this approach or are there some Java Design decisions that explains that?
So, Long story short: Is this not possible for a reason?