简体   繁体   中英

Java best practice: set System.out.println() on other method

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM