Java Constructors Pattern

I use the template quite a lot:

class Blah int a; double b; String c; Date d; public Blah(int a, double b, String c, Date d) { super(); // possibly this.a = a; this.b = b; this.c = c; this.d = d; } 

These are really many templates for something so simple. I was thinking of a universal factory object to do this with introspection, but it seems very evil (special cases, inheritance, and speed issues). You can use Guice, and the constructor generally skipped it, but then manually creating objects would be ugly.

Is this something I will have to live in Java for, or is there a way to avoid this pattern?

+6
source share
1 answer

Try using Lombok ( http://projectlombok.org/ )

You can create getters, setters, and constructors with simple annotations.

+5
source

Source: https://habr.com/ru/post/946063/


All Articles