Java method call on type object -


I want a method that takes an object as a parameter, and adds it to a simple list later , I want to call a method on this object, but the time of the hole, I do not want to define the object as a specific type, just type the object I know that the object in the object that I want to call I'm sure because of this To do that I pass the object with only that method. Something like this:

  Public Zero addElement (object obj) {elementlist.add (obj); }. . Elementlist.get (i) .SomeMethodIknowItHas ();   

However, it is not working, is there any way that I can force him to call that method?

If you do not really want to insert the object as a specific type, you can use the reflection Have to do.

However, this is generally considered bad behavior, and you should see if there is any way you can use that instead of generic with interface or base class. The fact is that you know that this kind of method is that it should implement an interface that tells the compiler that there is a method in it.

Comments