Adrian Preuss
Adrian Preuss

Reputation: 3113

Java redefine a method dynamically

Is it possible to define a method without extending classes?

((JComponent) c).paintComponents(Graphics a) {
    // Paint some one
};

Upvotes: 0

Views: 173

Answers (2)

Andy Brown
Andy Brown

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

Cortwave
Cortwave

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

Related Questions