Why concatenate strings with an empty value before returning the value?

Lachlan Lindsay :

I've seen in some java libraries when returning a string the value is concatenated with an empty value.

For example package java.io;

/**
 * The system-dependent default name-separator character, represented as a
 * string for convenience.  This string contains a single character, namely
 * <code>{@link #separatorChar}</code>.
 */
public static final String separator = "" + separatorChar;

Why not return only separatorChar?

Are strings the preferred datatype for return values? Give that this is only a char anyway why use a string datatype?

Are there any performance implications of doing this conversion?

Michael Bianconi :

One is a String, the other is char. It's useful to always be dealing with a String, rather than having to check if it's a char.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=139359&siteId=1