在valueOf()和newInstance()之间选择的标准是什么?

use*_*820 5 java coding-style factory-method

假设我有一个ObjectInfo类,其中包含Object name和Object type作为String.(我只是为了提出问题而做点什么.)

class ObjectInfo {
    String objectName;

    String objectType;

    private ObjectInfo(String objectName, String objectType) {
          this.objectName = objectName;
          this.objectType = objectType;
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我想提供一个静态工厂方法来创建这个类的实例,以下两种方法中的哪一种更好?为什么?

public static ObjectInfo newInstance(String objectName, String objectType) {
    return new ObjectInfo(objectName, objectType)    
}

public static ObjectInfo valueOf(String objectName, String objectType) {
    return new ObjectInfo(objectName, objectType)    
}
Run Code Online (Sandbox Code Playgroud)

基本上,我想问的是什么时候我们应该使用valueOf()&newInstance()?程序员社区中是否有任何约定?

-Ankit