Issues on Inheritance: Missing fields on ToString

785 views
Skip to first unread message

Nambi

unread,
May 12, 2011, 2:59:01 PM5/12/11
to Project Lombok
Looks like ToString implementation does not take super class fields
into account. Is this in pipeline for coming release.

How can I extend Lombok to fix this in meantime.

My code:
-------------

package org.nava.lombok;

import lombok.Data;
import lombok.EqualsAndHashCode;

public class LombokTest {

public static void main(String[] args) {

AbstractBean bb = new AbstractBean();
bb.setName("BaseBean");
System.out.println(bb);

Bean cb = new Bean();
cb.setName("ConcreateBean");
cb.setId(112);
System.out.println(cb);
}

}

@Data
class AbstractBean {

private String name;
}

@Data
@EqualsAndHashCode(callSuper = true)
class Bean extends AbstractBean {

private Integer id;

}
------------------------------------------------
The results are

AbstractBean(name=BaseBean)
Bean(id=112)

Where as I am expecting both name and id to be printed on the Bean

-Nambi

Philipp Eichhorn

unread,
May 12, 2011, 3:42:10 PM5/12/11
to Project Lombok
You need to explicitly tell lombok to include the super.toString()
via: @ToString(callSuper = true) .
Then you end up with the output:
Bean(super=AbstractBean(name=ConcreateBean), id=112) if I'm not
greatly mistaken.

further reading: http://projectlombok.org/features/Data.html

-Philipp
Reply all
Reply to author
Forward
0 new messages