Question about inline code segment
Not sure if this is in the appropriate topic, if not let me know where would be better, thankyou.
Fairly new to object oriented programming and even newer to Java. I've never seen code inlined like this before. I need help understanding what exactly is happening here. Is this segment of code overloading the constructor of the OnClickListener object?
Code Java:
OnClickListener l = new OnClickListener()
{
public void onClick(View v)
{
if (mPhoneIsSilent)
{
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
mPhoneIsSilent = false;
}
else
{
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
mPhoneIsSilent = true;
}
toggleUi();
}
};
Re: Question about inline code segment
Quote:
Is this segment of code overloading the constructor of the OnClickListener object?
No, it's extending OnClickListener if OnClickListener is a class, implementing OnClickListener if OnClickListener is an interface. It's an anonymous inner class:
Nested Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
What is overridden (or implemented) is the onClick(View) method.
Re: Question about inline code segment
Thank you. I looked all over the net for documentation about that but I didn't know what it was refered to as. (anonymous class)