Bru*_*ndo 2 string stringbuilder refactoring intellij-idea
我被指定对一个项目进行重构,我遇到了这种情况
this.path = DESTINY + deploy.name() + FILE_SEPARATOR + delivery.getSystem().getCode()
+ FILE_SEPARATOR + delivery.getName() + FILE_SEPARATOR + delivery.getEnviroment().getName();
Run Code Online (Sandbox Code Playgroud)
我想将它重构为这样的:
StringBuilder tmpPath = new StringBuilder();
tmpPath.append(DESTINY);
tmpPath.append(deploy.name());
tmpPath.append(FILE_SEPARATOR);
tmpPath.append(delivery.getSystem().getCode());
tmpPath.append(FILE_SEPARATOR);
tmpPath.append(delivery.getName());
tmpPath.append(FILE_SEPARATOR);
tmpPath.append(delivery.getEnviroment().getName());
this.path = tmpPath.toString();
Run Code Online (Sandbox Code Playgroud)
或者
StringBuilder path = new StringBuilder();
...
this.path.append(DESTINY);
this.path.append(deploy.name());
this.path.append(FILE_SEPARATOR);
this.path.append(delivery.getSystem().getCode());
this.path.append(FILE_SEPARATOR);
this.path.append(delivery.getName());
this.path.append(FILE_SEPARATOR);
this.path.append(delivery.getEnviroment().getName());
Run Code Online (Sandbox Code Playgroud)
最快的方法是什么?