r8mrag
Last Updated: February 25, 2016
·
2.702K
· 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

9257

Well done!!! You awesome =)

over 1 year ago ·
9329

Nice tip! thanks...

over 1 year ago ·
9955

remember this

over 1 year ago ·