Alternative to MoreObjects in Java 8 -
i want rid of dependency: import com.google.common.base.moreobjects;
is there simple and/or elegant way rewrite following tostring()
function using java 8 native functions?
@override public string tostring() { return moreobjects .tostringhelper(this) .add("userid", this.userid) .add("timestamp", this.timestamp) .tostring(); }
you can use stringjoiner
java.util
package.
example:
@override public string tostring() { return new stringjoiner(", ", classname.class.getsimplename() + "[", "]") .add("userid=" + userid) .add("timestamp=" + timestamp) .tostring(); }
Comments
Post a Comment