我想知道是否有办法通过将Class类型与对象一起存储来自动将对象转换为某种类型?我认为这可能是Java,但也许不是.
例如:
class StorageItem
{
private int itemcount;
StorageItem(int itemcount)
{
this.itemcount = itemcount;
}
int getItemCount()
{
return itemcount;
}
}
class Storage
{
private Class clazz;
private Object value;
public Storage(Class clazz, Object value)
{
this.clazz = clazz;
this.value = value;
}
//Is there a way such a call can be created to automatically cast
//the object to the class type and return that cast type in a
//generic way. The idea being that Storage knows what it …Run Code Online (Sandbox Code Playgroud)