Methods Summary |
---|
public static boolean | isNumber(java.lang.Class dataType)Demonstrates usage of isAssignableFrom on a class object.
return Number.class.isAssignableFrom(dataType);
|
public static void | main(java.lang.String[] args)Demonstration Method.
System.out.println("Using isAssignableFrom:");
useAssignable(InstanceOfDemo.OBJECT_SET);
System.out.println("\nUsing isInstance:");
useIsInstance(InstanceOfDemo.OBJECT_SET);
|
public static void | useAssignable(java.util.Set inputSet)Demonstrates use of isAssignableFrom on objects in a set.
final Iterator iter = inputSet.iterator();
Object obj = null;
while (iter.hasNext()) {
obj = iter.next();
if (obj != null) {
if (Number.class.isAssignableFrom(obj.getClass())) {
System.out.println(obj);
}
}
}
|
public static void | useIsInstance(java.util.Set inputSet)Demonstrates usage of isInstance on objects in a set.
final Iterator iter = inputSet.iterator();
Object obj = null;
while (iter.hasNext()) {
obj = iter.next();
if (Number.class.isInstance(obj)) {
System.out.println(obj);
}
}
|
public static void | useIsInstance2(java.lang.Class dataType, java.util.Set inputSet)Demonstration method for class comparison based on passed class and object.
if (dataType == null) {
throw new NullPointerException();
}
final Iterator iter = inputSet.iterator();
Object obj = null;
while (iter.hasNext()) {
obj = iter.next();
if (dataType.isInstance(obj)) {
System.out.println(obj);
}
}
|