Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Hi Pankaj, Nice explaination. One correction, it is written as ‘Notice that the clone method is overridden to provide a deep copy of the employees list.’ But clone method created shallow copy and not deep copy.
- Amit N
Program says List… but it is printing as hashmap… how it is possible? System.out.println("emps List: "+emps.getEmpList()); System.out.println("empsNew List: "+list); System.out.println("empsNew1 List: "+list1
- Vinod
Your tutorials arereally wonderful and easy to understand.I was wondering where can we use prototype pattern in real time.
- Supriya
what would happen if I would add one employee(“John”) in the list (list) and save it to the database, and from (list1) i want to remove the “John” but it would say it does not exist? can you please elaborate more onhere can we use this
- Kunal Bansal
Hi Pankaj, i can very well call the below 2 lines of code with creating a new object /calling a db emps.getEmpList().add(“John”); emps.getEmpList().remove(“Pankaj”); I havent understood the exact thing… can u please explain.
- Sashi
I got a doubt after implementing this design pattern. When I update database using changed list lets say List list = empsNew.getEmpList(); list.add(“John”); whith this list and I will get list1 like List list1 = empsNew1.getEmpList(); then I will get old list. So isn’t it have data inconsistency issue?
- Sandeep
what is use of implementing Cloneable interface in this example and suppose i removed cloneable interface then what will happened.it will clone object,i tried to remove cloneable interface but same output came,please explain
- salil
Dear Pankaj, I was experimenting with the code you provided here. Found something really weird that I couldn’t understand. Please check the following method. @Override public Object clone() throws CloneNotSupportedException { return new PlayersList(empList); } Instead of returning the ‘temp’ ArrayList, I returned the ‘empList’. output like this: emps HashMap : [Pankaj, Raj, David, Lisa] empsNew HashMap : [Raj, David, Lisa, John] empsNew1 HashMap : [Raj, David, Lisa, John] I think there is something that I have failed to understand. An explanation would be of great help. Thanks a lot for these nice, useful and easy to implement tutorials.
- Tahmid
Hi Pankaj, Could you please provide JDK example as well for prototype design pattern?
- Ganesh AC