Wednesday, 3 September 2014

JAVA How to Avoid Generic type Declaration for ArrayList and HashTable

instate of writing all time generic type declaration for creating ArrayList of any collection type, Java inheritance concept will always useful to create own ArrayList or any type of collection object to reduce task of all time generic form of object declaration 

Normal concept to use generic as : 

ArrayList<UserBean> userList = new ArrayList<UserBean>();

after doing some extra task as :

public class UserBeanArrayList extends ArrayList<UserBean>{

}

cool implementation without generic type declaration, its looking so simple

UserBeanArrayList userArrayList = new UserBeanArrayList();

___________________________________________________________________________________
Why i am doing Extra Task
  • Simple object declaration
  • override some method of ArrayList class as per business logic is possible here
  • add some additional property and method along with list object are also permitted here like normal class
  • Also make this ArraList is singleton class through out your application like other singleton class

No comments:

Post a Comment