I found this code at a search on Google:
public interface Combine {
// Combines 2 objects
public Object combine(Object o1, Object o2);
}
and I would like to combine two objects in the main class using the above code. How would I declare a Combine object to serve my purpose?
You would create a class that implements the
Combineinterface, and overridepublic Object combine(Object o1, Object o2)to do whatever it means in your case to combine those two parameters.Look at Marcelos answer for a fancier solution using generics – this allows you to pass in the specific types you’re interested in, and not just
Object.