是否有可能在Java中重写'的toString'为对象的数组? [英] Is it possible in Java to override 'toString' for an Objects array?

查看:331
本文介绍了是否有可能在Java中重写'的toString'为对象的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在Java中重写一个toString一个对象数组?

Is it possible in Java to override a toString for an Objects array?

例如,假设我创建了一个简单的类,用户(它并没有真正无论哪个阶级是因为这是一个普遍的问题)。有没有可能,一旦客户创建一个用户[] 阵列和客户端使用 System.out.print(阵列),这将不打印数组的地址,而是一个定制的的toString()

For example, let's say I created a simple class, User (it doesn't really matter which class is it since this is a general question). Is it possible that, once the client creates a User[] array and the client uses System.out.print(array), it won't print the array's address but instead a customized toString()?

PS:我当然不能只是覆盖的toString()在我的课,因为它涉及到单一实例

PS: of course I can't just override toString() in my class since it's related to single instances.

推荐答案

没有。当然,你可以创建一个静态方法User.toString(用户[]),但它不会被隐式调用。

No. Of course you can create a static method User.toString( User[] ), but it won't be called implicitly.

这篇关于是否有可能在Java中重写'的toString'为对象的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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