Reputation: 44240
Here is an example
JPanel panel = new JPanel(){
@Override
protected void paintComponent(Graphics g){
// do stuff
}
@Override
public Dimension getPreferredSize(){
// do stuff
}
};
Would this just be a variation of an anonymous inner class, or is it something else entirely?
Upvotes: 3
Views: 409
Reputation: 71
You may be confused about the anonymity of the class because at first blush it looks like you're defining panel to be an instance of JPanel. However, that's not what you are doing. Instead you are defining a sub-class of JPanel, which is a new class and creating panel to be an instance of this new sub-class. What is the name of this new class? Well, it doesn't have one and hence that's what makes it anonymous!
Upvotes: 5