Super Ninja Tips for Java Folks : No more getters setters.
2 posters
Page 1 of 1
Super Ninja Tips for Java Folks : No more getters setters.
Hey Guys, Come back to get some votes. LOL,
You java guys probably bored writing getter and setter over and over. You want something like c# get; set;
features. I think here I can help you. There is a project name, “project Lombok”.
With this, you won’t need to write getters and setters any more. Lombok will do it for you.
To get the things running you need to follow me:
- Download Lombok: http://projectlombok.org/download.html
- Get the jar, double click on it; it will do
everything for you, but just for being sure, read what is written in there.
- Now in your eclipse/netbeans/sts, you need to add the Lombok jar at project classpath, that’s all, no big deal. Create a folder in your project, name it libs, and paste the lobbok .jar on it. Now click on the project, select properties, select java build path and then click on the libraries and then click on Add JARs.
We are almost done; now let’s see an example –
I think it is something really interesting.
It has more interesting
features, try it: http://projectlombok.org/features/index.html
Let’s not mess up our java source code writing getters and setters over and over.
You java guys probably bored writing getter and setter over and over. You want something like c# get; set;
features. I think here I can help you. There is a project name, “project Lombok”.
With this, you won’t need to write getters and setters any more. Lombok will do it for you.
To get the things running you need to follow me:
- Download Lombok: http://projectlombok.org/download.html
- Get the jar, double click on it; it will do
everything for you, but just for being sure, read what is written in there.
- Now in your eclipse/netbeans/sts, you need to add the Lombok jar at project classpath, that’s all, no big deal. Create a folder in your project, name it libs, and paste the lobbok .jar on it. Now click on the project, select properties, select java build path and then click on the libraries and then click on Add JARs.
We are almost done; now let’s see an example –
- Code:
public class Product {
@Getter
@Setter
private int productId;
@Getter
@Setter
private String name;
@Getter
@Sette
private String Description;
@Getter
@Setter
private BigDecimal Price;
@Getter
@Setter
private String Category;
@Override
public String toString() {
return "Product [productId=" productId ", name=" name
", Description=" Description ", Price=" Price
", Category=" Category "]";
}
}
- Code:
public class Apps {
public static void main(String[] args) {
Product p = new Product();
p.setProductId(1);
p.setName("java");
p.setDescription("java programmers are monkey");
p.setPrice(new BigDecimal(1000));
p.setCategory("Programming language");
System.out.println(p.toString());
}
}
I think it is something really interesting.
It has more interesting
features, try it: http://projectlombok.org/features/index.html
Let’s not mess up our java source code writing getters and setters over and over.
Lombok only works with java 6 or higher version.
Similar topics
» Java Tutorial: Using Two Java Reference Keywords, this and super
» Java, Introduction to SUPER and THIS
» Visual Studio 2010 Professional - Tweaking and some useful tips
» Some Eclipse Tips
» About Java 3D
» Java, Introduction to SUPER and THIS
» Visual Studio 2010 Professional - Tweaking and some useful tips
» Some Eclipse Tips
» About Java 3D
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford