我有一个方法可以传递任何类型的参数。我的目标是找到传递的参数是否是数字,然后找到数字的绝对值。传递的对象可以是double、Integer、string、long等。
演示.java
public class Demo{
public Object abs(Object O){
if(Number.class.isAssignableFrom(O.getClass())){
// Check the type of the number and return the absolute value of the number
}
else
{
return -1
}
}