-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clone() method does not declare throws CloneNotSupportedException #98
Comments
Damian, I am not sure if I understand your issue correctly. May I ask you for clarification?
I guess you want to create a builder class hierarchy. Is that right? If so, why? |
Hi Michael,
Eg.
so in test I can use method from abstract class when using concrete builder:
In that case I can reuse |
Damian, I have to apologize that I haven't answered to your last comment for so long. I had a lot of work to do. So, going back to your issue, I have created a sample project and just entered the following classes: public abstract class Animal {
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
@GeneratePojoBuilder
public class Dog extends Animal {
private int speed;
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
} I hope that this is what you are talking about, isn't it? Animal is abstract and Dog is a subclass of Animal. Please note, that the As you see, the generated DogBuilder can be used exactly as you have required: new DogBuilder().withSpeed(34).withAge(2).build(); Since there is only one builder (DogBuilder), you don't have any problems with the Does this solve your issue? |
Hi Michael, In the meantime I have tried to prepare PR to extend pojobuilder and cover this issue. Lucky me I was working with real project so I could test all cases. Finally I gave up because of the following issue:
Having two above (or maybe only first is the key) I found that external tool which you use to list available fields does not list Perfect solution for me would be to be able to list all fields (no matter what modifier it has and what methods related to this fields are implemented). If the attribute has setter then setter method can be used to change value, otherwise reflection. |
Hi Michael, I got the same problem, when I was trying to use a factory returning the appropriate builder for subclasses of a common type. The correct As a workaround I tried to let the builders just extend the base class builder -- of course I know that this generates duplicate fields in each builder type of the inheritance chain, but in my situation this is only for testing purpose, so I don't care. ` @GeneratePojoBuilder(withBaseclass=VehicleBuilder.class) @GeneratePojoBuilder(withBaseclass=VehicleBuilder.class) public class BuilderFactory { public class Factory { |
I have not read all of the above but #132 includes |
This should now be fixed in PB 3.6.0. |
I have two classes Animal and Dog. Animal is declared as abstract and Dog extends Animal.
i was trying to add builders for both but I found that Animal.
clone()
method does not declareCloneNotSupportedException
in method definition so sub class Dog cannot be compiled with success:and the problem is that parent class Animal declares
while it should (as it is for
java.lang.Object
)Solutions:
clone()
method should be implemented or notwithBaseclass
)The text was updated successfully, but these errors were encountered: