I've just recently stumbled upon this when trying to simplify my class' constructors that have about 50% of identical codes. It seems like I couldn't re-use my former constructor definition (which handles initialization) from another constructor that overloads it.
For the sake of clarity, this is what I've been trying to say:
public MusicOrganizationHelper(Context context)
{
mContext = context;
// More object initializations using 'context'..
}
public MusicOrganizationHelper(Context context, ArrayList<String> fileUris)
{
MusicOrganizationHelper(context); // Why can't I do this?
for (String uri : fileUris) {
if (uri != null && !uri.equalsIgnoreCase("")) {
try {
AudioFile audioFile = read(uri);
mAudioFileMap.put(audioFile, audioFile.getTagOrCreateAndSetDefault());
} catch (CannotReadException e) {
e.printStackTrace();
}
}
}
}
I know this could be easily produced by making some sort of private void init(context) method but I'm just curious: why can't I call constructors like any other method even from within its class definition? They seems pretty similar to me (them constructors and 'peasant' methods).
I'm sorry if this turns out to be an obvious thing. I'm relatively new to Java and OOP in general.
Thanks in advance!
this(context)....?