Showing posts with label how to maintain a list of static class and the instanciate from them. Show all posts
Showing posts with label how to maintain a list of static class and the instanciate from them. Show all posts

Thursday, February 26, 2015

how to maintain a list of static class and the instanciate from them
































































hello,
































































I have a list of uninstanciated class types and I wanted to call a static function from these































































"Class<? extends PropControl>" (without using reflection) that would create a new corresponding object instance































































but it appears I cant do that in java
































































so now I want to create a factory that takes a class type as aparameter to create the corresponding object instance
































































but this code dont compile:
































































































Java Code:






































































public PropControl Create(Class<? extends PropControl> cls)
{
if(cls==HouseControl.class) <---- ERROR
{
here I create a new instance of HouseControl (that inherits PropControl)
}
}




































































I get this error :































incomparable types: Class<CAP#1> and Class<HouseControl>































































where CAP#1 is a fresh type-variable:































































CAP#1 extends PropControl from capture of ? extends PropControl
































































how do I achieve this ?
































































thanks































































































































how to maintain a list of static class and the instanciate from them
































hello,
































I have a list of uninstanciated class types and I wanted to call a static function from these































"Class<? extends PropControl>" (without using reflection) that would create a new corresponding object instance































but it appears I cant do that in java
































so now I want to create a factory that takes a class type as aparameter to create the corresponding object instance
































but this code dont compile:
















































Java Code:





































public PropControl Create(Class<? extends PropControl> cls)
{
if(cls==HouseControl.class) <---- ERROR
{
here I create a new instance of HouseControl (that inherits PropControl)
}
}



































I get this error :















incomparable types: Class<CAP#1> and Class<HouseControl>































where CAP#1 is a fresh type-variable:































CAP#1 extends PropControl from capture of ? extends PropControl
































how do I achieve this ?
































thanks































































how to maintain a list of static class and the instanciate from them
















hello,
















I have a list of uninstanciated class types and I wanted to call a static function from these















"Class<? extends PropControl>" (without using reflection) that would create a new corresponding object instance















but it appears I cant do that in java
















so now I want to create a factory that takes a class type as aparameter to create the corresponding object instance
















but this code dont compile:
























Java Code:




















public PropControl Create(Class<? extends PropControl> cls)
{
if(cls==HouseControl.class) <---- ERROR
{
here I create a new instance of HouseControl (that inherits PropControl)
}
}


















I get this error :







incomparable types: Class<CAP#1> and Class<HouseControl>















where CAP#1 is a fresh type-variable:















CAP#1 extends PropControl from capture of ? extends PropControl
















how do I achieve this ?
















thanks































how to maintain a list of static class and the instanciate from them








hello,








I have a list of uninstanciated class types and I wanted to call a static function from these







"Class<? extends PropControl>" (without using reflection) that would create a new corresponding object instance







but it appears I cant do that in java








so now I want to create a factory that takes a class type as aparameter to create the corresponding object instance








but this code dont compile:












Java Code:











public PropControl Create(Class<? extends PropControl> cls)
{
if(cls==HouseControl.class) <---- ERROR
{
here I create a new instance of HouseControl (that inherits PropControl)
}
}









I get this error :



incomparable types: Class<CAP#1> and Class<HouseControl>







where CAP#1 is a fresh type-variable:







CAP#1 extends PropControl from capture of ? extends PropControl








how do I achieve this ?








thanks















how to maintain a list of static class and the instanciate from them




hello,




I have a list of uninstanciated class types and I wanted to call a static function from these



"Class<? extends PropControl>" (without using reflection) that would create a new corresponding object instance



but it appears I cant do that in java




so now I want to create a factory that takes a class type as aparameter to create the corresponding object instance




but this code dont compile:






Java Code:






public PropControl Create(Class<? extends PropControl> cls)
{
if(cls==HouseControl.class) <---- ERROR
{
here I create a new instance of HouseControl (that inherits PropControl)
}
}




I get this error :

incomparable types: Class<CAP#1> and Class<HouseControl>



where CAP#1 is a fresh type-variable:



CAP#1 extends PropControl from capture of ? extends PropControl




how do I achieve this ?




thanks