I need to be able to make a method which performs a generic Object type comparison:

boolean compare(Object obj1, Object obj2)
if(obj1 type == obj2 type)
return true;
return false;


Image var1, var2;
int var3, var4;

test1 = compare(var1, var2);
test2 = compare(var3,var4);
test3 = compare(var1,var4);
test4 = compare(var2, var3);

and the result should be: test1=true, test2=true, test3=false, test4=false.

How can I do?

I think I can't use "istanceof", because in this case I must know the type of one of the two object in the comparison. In this case the comparison would be no more generic.