Reputation: 3113
Is it possible to define a method without extending classes?
((JComponent) c).paintComponents(Graphics a) {
// Paint some one
};
Upvotes: 0
Views: 173
Reputation: 19161
No, but if you are just trying to reduce the number of classes you have to define you could use an anonymous class
JComponent c = new JComponent() {
@Override public void paintComponent(Graphics g) {
// do stuff
}
}
Upvotes: 3
Reputation: 4907
No. It's impossible. Java isn't interpreted programming language. It's compiled.For example you can do it in Ruby.
Upvotes: -1