gpt4 book ai didi

java - java中从object.toString获取类对象

转载 作者:行者123 更新时间:2023-12-01 06:55:47 26 4
gpt4 key购买 nike

我想从 object.toString 获取类对象(不重写类中的 toString 方法)。

我知道反射会给出该对象,但它会创建一个我不想要的类的新实例。

最佳答案

I know the reflection will give the object but it creates a new instance of the class which I don't want.

不,真的不会。

只要打电话

foo.getClass();

而不是

foo.toString();

这肯定不会创建该类的新实例。它只会获得一个Class引用。

关于java - java中从object.toString获取类对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12376110/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com