-4

How to run a anonymous method from class .

For instance,

I have a class

Class A {
   void Save(){
     //do something
   }
}


Class B {
       void Save(){
         //do something
       }
    }

When I getting the object from somewhere:

Object something = (could be A or B both because object can accept anything.)
something.Save() //doesn't work. To solve this I could use inheritance(abstract class or Interface) but if I want to do it anonymously

Like in VB

object Form = SomeRandomForm
Form.Save() // anonymously no need to inherit   

Is it possible in java?

Md. Alim Ul Karim
  • 2,401
  • 2
  • 27
  • 36

1 Answers1

3

I don't know what it is exactly that you mean (some code might help), but basically you just define the generics on the interface and the concrete type on the panels:

interface MyInterface<T> { ... }

class StringPanel extends JPanel implements MyInterface<String> { ... }

The rest is up to you.

Thomas
  • 87,414
  • 12
  • 119
  • 157