【发布时间】:2013-04-05 06:16:45
【问题描述】:
我有一个方法可以传递任何类型的参数。我的目标是找到传递的参数是否是数字,然后找到数字的绝对值。传递的对象可以是double、Integer、string、long等。
Demo.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
}
}
【问题讨论】:
-
stackoverflow.com/questions/106336/… 应该回答这个问题。