• Post Reply Bookmark Topic Watch Topic
  • New Topic

Singleton

 
norton stanley
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String fullName = PATH + "." + name;
Class cl= Class.forName(fullName);
if(name.equalsIgnoreCase("MobileSearch")){
if(msearchType==null){
msearchType=(SearchInterface)cl.newInstance();
}
return msearchType;

}
if(name.equalsIgnoreCase("BookSearch")){
if(bsearchType==null){
bsearchType=(SearchInterface)cl.newInstance();
}
return bsearchType;

}
Am using reflection in the above code.I wanna get rid of the if statements to create objects.How do i do it.please help.
Thanks in advance.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!