从对象转换为原始类 [英] Convert from Object to Original Class
本文介绍了从对象转换为原始类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在对象
中存储 Entry
类的实例。
Entry newentry = new Entry(j, 0.0);
Object test = newentry;
如何将 test
进入 Entry
类以访问 Entry
类方法 getValue()
How can I convert the test
Object back into an Entry
class to access the Entry
class method getValue()
?
推荐答案
Typecast it:
Typecast it:
Entry newentry = new Entry(j, 0.0);
Entry test = (Entry) newentry;
此外,如果 getValue
>类方法,您不需要实例即可访问它,您可以直接调用它:
Also, if getValue
is a class method, you don't need an instance to access it, you can call it directly:
Object x = Entry.getValue();
这篇关于从对象转换为原始类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文