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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

python - RuntimeWarning: PyOS_InputHook is not available for interactive use of PyGTK -