project lombok!

12
Project Lombok Spices up your java! Mehdi Hassan Team Lead Etilize Pvt. Ltd.(GfK)

Upload: mehdi-haryani

Post on 24-Dec-2014

876 views

Category:

Technology


10 download

DESCRIPTION

The introduction of Project Lombok, a combination compile-time and development-time code generator, has made Java POJO verbosity history. Add Lombok to your daily coding practices, and you won't go back.

TRANSCRIPT

Page 1: Project Lombok!

Project Lombok

Spices up your java!

Mehdi Hassan

Team Lead

Etilize Pvt. Ltd.(GfK)

Page 2: Project Lombok!

Problems of the Industry

Boiler Plate Code

Syntax Verbosity

Non Standardization

Not following the standard code conventions!!

Human Error/Dependency

Repeatable things (defining Getters, Setters etc.)

Project Lombok!

Page 3: Project Lombok!

Demo Video

Taken from http://projectlombok.org/

Gives an idea what Project Lombok is and how it can be installed.

Simple Demo of few Features.

Project Lombok!

Page 4: Project Lombok!

Features

@Getter, @Setter, @ToString, @EqualsAndHashCode, @Data

@NoArgsConstructor, @RequiredArgsConstructor and @AllArgsConstructor

@Cleanup, @Synchronized

@Log

@Delegate

val

Project Lombok!

Page 5: Project Lombok!

@Getter and @Setter

Project Lombok!

Automatic Generation of getters and setters.

Method will be public unless you explicitly specify an AccessLevel

@Getter and/or @Setter annotation on class

Disable getter/setter generation for any field by using the special AccessLevel.NONE

@NotNull for nullity check

Demo

Page 6: Project Lombok!

@ToString

Project Lombok!

Generates a default implementation of the toString() method

Parameters

Demo

Page 7: Project Lombok!

@EqualsAndHashCode

Generates hashCode and equals implementations from the fields (non-static, non-transient)

Parameters

Demo

Project Lombok!

Page 8: Project Lombok!

Constructor level Annotations

@NoArgsConstructor, @RequiredArgsConstructor, @AllArgsConstructor

Generates constructors that take no arguments, one argument per final / non-null field, or one argument for every field.

Specialized constructor can be made. Compile-time error in case of any conflicts.

Demo

Project Lombok!

Page 9: Project Lombok!

@Data

All together now: A shortcut for @ToString, @EqualsAndHashCode, @Getter on all fields, @Setter on all non-final fields, and @RequiredArgsConstructor

Included annotations with changed parameters can be defined along with @Data

Project Lombok!

Page 10: Project Lombok!

@Cleanup

Automatic resource management: Call your close() methods safely with no hassle.

Example: @Cleanup InputStream in = new FileInputStream("some/file");

If the type of object you'd like to cleanup does not have a close() method, but some other no-argument method like dispose() so write it as

@Cleanup("dispose") TestClass t = new TestClass();

Project Lombok!

Page 11: Project Lombok!

Logger Annotations!

Generate a logger field with name “log”

Four options

@CommonsLog

@Log

@Log4j

@Slf4j

Project Lombok!

Page 12: Project Lombok!

And Lot More!!!

Some other supported features like @Delegate, @Synchronized, val etc.

More to come soon!

Open Source

Details can be found at http://projectlombok.org/

Project Lombok!