This might be simple for seasoned java developers but I just cant seem to figure it out. I read a post from here. The code was
View v = new View(this) {
@Override
protected void onDraw(Canvas canvas) {
System.out.println("large view on draw called");
super.onDraw(canvas);
}
};
It was an Android question. Here the user creates an instance of a view and overrides a method in a single line. Is there a name for this kind of coding?
My second doubt is, he overrides a protected method from another package. Isn't protected mean package private. I know this will work as I tried it out but I just couldn't figure out why it worked. So why is this code working?
I did try to google this and search in SO before asking but couldn't figure out an answer.