覆盖使用重写的toString()的toString() [英] Override of toString() that makes use of the overridden toString()

查看:72
本文介绍了覆盖使用重写的toString()的toString()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上这就是我想要实现的目标。

Basically this is what I am trying to achieve.

classname @ address(?)[original toString()],对象的名称,对象的年龄

classname@address(?)[original toString()], object's name, object's age

@Override public String toString()
{
return String.format("%s , %s , %d", this.toString(), this.getName(),this.getAge());
}

问题, toString()递归调用。

我无法调用 super.toString()因为那不是我想要的。我想要'这个'来调用原来的 toString()

I can't call super.toString() because that's not what I want. I want 'this' to call the original toString().

this.super.toString() 

由于显而易见的原因不起作用。

doesn't work for obvious reasons.

我已经没法了,一旦方法被覆盖,这可以做到吗?即打电话给原来的实施?

I'm running out of steam, can this be done once a method gets overridden? I.e. call the original implementation ?

(我的编辑)基本上我需要的是:覆盖toString以显示'this'对象的两个属性,我也想让'this'调用原来的toString 。

(my edit) Basically what I need is: override toString to display two properties of 'this' object, and I also want to have 'this' call the original toString.

这不是项目或工作。用Java语言玩(学习)。谢谢

This is not a project , or work. Just playing(learning) with Java language. Thanks

推荐答案

您正在寻找 super.toString()

这篇关于覆盖使用重写的toString()的toString()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆