I have some weird requirment I need to load a class dynamically,
here I have an Interface
public interface House
{
public Object loadHouseModel(String type);
public Object loadHouseSpace(String type);
}
now the desired class will implement this interface
public class DuplexHouse implements House
{
public Object loadHouseModel(String type)
{
///Method body goes here
}
public Object loadHouseSpace(String type)
{
///Method body goes here
}
}
Now my requirement is that I need to load DuplexHouse or whatever the class which implements House
Requirment is that DuplexHouse class name I will get it from properties and All I know is The class name I get will Implement the House Interface.
so my propertie looks like this
type_house=xx.xx.xxx.DuplexHouse,xx.xx.xx.TruplexHouse,..etc
Based on the type of House I need to load corresponding house object
So in my main class
Class cl = Class.forName(xx.xxx.xxx.DuplexHouse);
My requirment is I want House Instance which internally holds DuplexHouse object
How can I do that ??
Classobject? Is anything preventing you from just instantiatingHouse house = new DuplexHouse()?ClassName<T extends House>HousewithDuplexHousecauseDuplexHouseis unknow that time I take this class name from property. All I know is thatDuplexHouseimplementsHouseClass.newInstance()House house = (House)Class.forName("xxx.xxx.xxx.DuplexHouse").newInstance();?