In what format does ToStringBuilder.reflectionToString(Object) display dates?

こ雲淡風輕ζ 提交于 2019-12-11 05:48:31

问题


In what format does ToStringBuilder.reflectionToString(Object) display dates? According to the Apache Commons Lang 2.4 documentation, ToStringBuilder.reflectionToString(Object) delegates to ReflectionToStringBuilder.toString(Object) which "Builds a toString value using the default ToStringStyle through reflection." So, in what format does the default ToStringStyle display dates?


回答1:


DefaultToStringStyle is just an immutable subclass of ToStringStyle, so it falls back on that for handling. ToStringStyle does not have any special handling for dates, so it just uses Date's toString.

However, there is actually an example of adding it.




回答2:


public class ToStringBuilder {

    /**
     * The default style of output to use.
     */
    private static ToStringStyle defaultStyle = ToStringStyle.DEFAULT_STYLE;

The default toString style. Using the Person example from ToStringBuilder, the output would look like this:

Person@182f0db[name=John Doe,age=33,smoker=false]


来源:https://stackoverflow.com/questions/4198253/in-what-format-does-tostringbuilder-reflectiontostringobject-display-dates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!