-4

I have pojo classes as shown below.

public class Car {
    private Engine engine;
    private List<Wheel> wheelList;
}

I am using Below pojo classes as parameters in "Car" pojo class.

public class Engine {
    private int power;
    private int type;
}

public class Wheel {
    private int size;
    private int type;
    private int colour;
}

Can you please help how to write builder pattern using java 8 lambda or lombok.

Java Learing
  • 269
  • 3
  • 11
  • 26
  • 3
    Do you have a plan of what you are doing? How do you want lambdas to fit in here? I'd recommend [reading up on the pattern first](https://en.wikipedia.org/wiki/Builder_pattern). Right now this is basically another `plzsendtehcodez` question, and it isn't entirely clear what you want. – Salem Jul 04 '17 at 14:37
  • 1
    I'd recommend forgetting about lambdas for now. Can you write the builder? Do that first. – duffymo Jul 04 '17 at 14:40
  • 2
    Prior to asking the question, please first research the topic and then come back with a question of you have a specific problem. There is at least 10 articles on using lambdas for builders when you google search "Java 8 lambda builder pattern" right on the first page of results. – Strelok Jul 04 '17 at 14:40
  • 1
    Editing the question and title to include "or lombok" isn't going to change much - there is a lack of information here. – Salem Jul 04 '17 at 14:42

1 Answers1

2

The builder patten is often used to construct objects with many properties. It makes it easier to read initialisations by having parameters named at the callsite, while helping you only allow the construction of valid objects.

Builder implementations tend to either rely on the constructed object being mutable, and setting fields as you go, or on duplicating all the settable fields within the builder.

Since Java 8, I find myself frequently creating lightweight builders by defining an interface for each initialisation stage.

you should definitely read this -

http://benjiweber.co.uk/blog/2014/11/02/builder-pattern-with-java-8-lambdas/

Stacy Chen
  • 221
  • 1
  • 5