Hi to all,
Hope you all will be fine. Actually i want to ask that we have a option to initialize variables in the constructor then why we use initialization block for it? Is there any efficiency issue in using initialization block?
Like i used this code
But i can also do it in the constructor. like i make a method and call it from the constructor in which i write down the above code.Code:/** Creates a new instance of EmailContent */ public EmailContent() { } //end of constructor //Initialization Block // load the values for <h:selectOneMenu> { emailEvents = new ArrayList<SelectItem>(); //The first item is a "no selection" item //new SelectItem(Object value, String label, String description, boolean disabled, boolean escape, boolean noSelectionOption) ) emailEvents.add(new SelectItem(null, "Pick a Email Event:", "", false, false, true)); ArrayList returnedEmailEventGrid = (ArrayList)email_Event.getEmailEventGrid(); //Check for Successfull completion if (Integer.parseInt(returnedEmailEventGrid.get(0).toString()) == 0) { for (int i = 1; i < returnedEmailEventGrid.size(); i++) { ArrayList returnRecord = (ArrayList) returnedEmailEventGrid.get(i); emailEvents.add(new SelectItem(returnRecord.get(0).toString(), returnRecord.get(1).toString())); } //end of for() } //end of if } //end of block
Am i using initialization block right here or there is no need to use initialization block in my code?
Thanks




Reply With Quote