从文件中读出一个Object,怎样知道这个Object具体是什么类型(有代码),只能用Instanceof吗?
从下面函数读出一个Object
public static Object readAnObjectFormAFile(String filepath)
{
File file = new File(filepath);
Object obj = null;
if (file.exists() == false)
return null;
try
{
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
obj = ois.readObject();
ois.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
return null;
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
return null;
}
return obj;
}
请问怎样才可以知道这个Object具体是什么类型.
是不是要用if(obj instanceof String)这类的方法来得到?
如果读出的是Set,Map这类的,怎样知道Set和Map的key和Value是什么类型?