The above suggestion doesn't compile. I think you're looking for:
Code:
class Test
{
public static void main(String[] args)
{
System.out.println("\n-=-= Begin Compare test =-=-");
String str1 = new String("abc");
String str2 = new String("bca");
Integer int1 = new Integer(5);
System.out.println("should be true: "+compare(str1,str2));
System.out.println("should be false: "+compare(str1,int1));
}
public static boolean compare(Object obj1, Object obj2)
{
boolean isEqual = false;
if ( (obj1.getClass()).isInstance(obj2) ) {
isEqual = true;
}
return isEqual;
}
}
Bookmarks