Return same instance of an object each time
This is the situation, I have a param value and based on that I need to
return a class instance. I want that on each invocation I return the same
object.
obj1 and obj2 implement the same interface.
class Engine {
public commonInterface getObj(int param) {
switch(param) {
case 1 : return obj1;
case 2 : return obj2;
}
}
}
How do I achieve this (I understand it's within a JVM)?
No comments:
Post a Comment