I have read that in Java interfaces can't be instantiated (in the documentation, Interfaces). Runnable, by definition is an interface which should be implemented by some class. But in the following piece of code from one of my Android applications I see that an empty constructor - Runnable()...(I am not sure if it is a constructor) has been used, and an instance has been created - getStatus.
final Runnable getStatus = new Runnable()
{
public void run()
{
TextView uat = (TextView) findViewById(R.id.useAndThrow);
uat.setText(MyThread.getStatus());
return;
}
};
What I have come to know:
- This is perhaps an example of anonymous class.
- The instance is not actually of interface.
But I am not able to connect the dots. Assuming that the above code was inside the myActivity class, what is being instantiated and how is this anonymous class?
A bit of detail would be great.