質問

I would like to map System.out.println on another function, such as:

public static void puts(Object o) { System.out.printl(o); }

This goes against some Java best-practice, or can have any drawbacks I did not think about?

役に立ちましたか?

解決

You can do that if you want. When you call the method, it will work the same as System.out.println, in most cases.

The problem is if you try this:

puts(new char[] {'h', 'e', 'l', 'l', 'o'});

If you do that with System.out.println, you will get hello. But if you do it with puts, you get something like this:

[C@812f71

If you don't print char[]s, you will be just fine.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top