[フレーム]
Last Updated: February 25, 2016
·
3.264K
· jxcoder

Java Tip #1. Stop to use "toString" method!

When you need to get string value of some object you should use String.valueOf method.
The String.valueOf method is null-safe and more clear way to get string value of the target object.

class SomeClass {
 @Override public String toString() {
 return "String value of SomeClass instance!"
 }
}

public class Main {
 public static void main(String[] args) {
 SomeClass someClassInstance = new SomeClass();

 System.out.println(String.valueOf(someClassInstance));
 }
}

3 Responses
Add your response

Well done!!! You awesome =)

over 1 year ago ·

Nice tip! thanks...

over 1 year ago ·

remember this

over 1 year ago ·

AltStyle によって変換されたページ (->オリジナル) /