Is it acceptable to name a named constructor valueOf that may return null in some cases?
For example, bar() is a named constructor that may return null if the argument is null.
class Foo {
public static Foo bar(String value) {
if (value == null)
return null;
else
return new Foo();
}
}
Would it be against the Java conventions to name it valueOf() instead? If not, I’m moving it to a helper.
EDIT: This method is a helper and must return null if the value is null for my needs.
Since that’s not actually a constructor, you can do whatever you want with it. But you might want to think about throwing a
NullPointerExceptioninstead of returningnullif you are worried about your callers.