At fisrt,thanks for the tips of Xia,I just run the situation he described.
When we want to print the properties of POJO, we can override the function toString() for conveninence , here is my testing code:
Created a object Student:
package mysrc;
import java.io.Serializable;
import org.apache.commons.lang.builder.ToStringBuilder;
public class Student implements Serializable{
int id;
String name;
//construct
Student (){
}
Student(int id,String name){
this.id = id;
this.name = name;
}
//override
public String toString(){
return ToStringBuilder.reflectionToString(this);
}
//the different way to implement this function
public String toStr(){
return new ToStringBuilder(this).append("id",id).append("name",name).toString();
}
}
Then test these two methods:
package mysrc;
public class ToStringTest {
public static void main(String args[]){
Student stu = new Student(10086,"tanglei");
System.out.println(stu.toString());
System.out.println(stu.toStr());
}
}
Then the result is :
mysrc.Student@a62fc3[id=10086,name=tanglei]
mysrc.Student@a62fc3[id=10086,name=tanglei]
Ok,that's all
分享到:
相关推荐
• Simplify unit testing of all your code—and improve integration and system testing • Delineate intent and implementation to promote more reliable and scalable testing • Overcome confusion and ...
windows api override testing tool, windows API 调试工具 非常有用的windows api调试工具 是破解或调试必须的
Feedforward, cascade, override, and single-variable inferential control approaches One and two degree of freedom Internal Model Control Model State Feedback and PI/PID Implementations of IMC ...
override abstract virtual interface比较
静态(static)方法重写(override)
override and overload difference
c# override new base 关系
Basic testing of the survey detail pages 119 Customizing the admin add and change survey pages 122 Developing a custom survey form 122 Configuring admin to use the custom form 123 Testing the ...
resource override
在使用eclipse开发时有时会遇到Override错误,这个错误已得到解决,不信你下载个试试?
NULL 博文链接:https://thaipine.iteye.com/blog/2354220
现象: … java: 1801: method does not override a method from its superclass @Override… 原因: Eclipse is defaulting to Java 1.5 and you have classes implementing interface methods (which in Java 1.6 ...
Lua中没有类的概念,但是程序猿说要面向对象,然后就有类。程序猿说要继承 和override,然后就有了继承 和 override 。
Lua中没有类的概念,但是程序猿说要面向对象,然后就有类。程序猿说要继承 和override,然后就有了继承 和 override 。
Delphi面向对象:overload与override[文].pdf
对Java中@override个人理解阐述,希望能帮大家更好理解。
了解何时使用 Override 和 New 关键字(C# 编程指南)
有一些收集的demo演示,可以很好的立即其不同情况的使用和区别
覆盖装饰器 ES7 的简单@Override装饰器。 用法 启用阶段0或es7.decorators在巴别,然后标记该意图覆盖超类与性质性质@Override 。 class A { ...// Error: b does not override a member of its superclass
override和重载的区别 希望对大家有帮助