Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class 如何在Java/Groovy中获得基于继承的类实例_Class_Inheritance_Groovy_Reflection - Fatal编程技术网

Class 如何在Java/Groovy中获得基于继承的类实例

Class 如何在Java/Groovy中获得基于继承的类实例,class,inheritance,groovy,reflection,Class,Inheritance,Groovy,Reflection,我有以下接口继承方案: Category -> PortalCorp | Portal365 以及以下接口: Oracle | MsSql | PostgreSql 最后是具体的单例类(为简单起见,仅限PortalCorp): 我正在编写一个函数来获取一个类的具体实例。作为参数,我们传递PortalCorp或Portal365类。我想它可以根据继承标准来完成 def <T extends Category> T getImpl(Class<T> category

我有以下接口继承方案:

Category -> PortalCorp | Portal365
以及以下接口:

Oracle | MsSql | PostgreSql
最后是具体的单例类(为简单起见,仅限PortalCorp):

我正在编写一个函数来获取一个类的具体实例。作为参数,我们传递
PortalCorp
Portal365
类。我想它可以根据继承标准来完成

def <T extends Category> T getImpl(Class<T> category)
{
        Category queryGetter

        if (DDLTool.isOracle())
        {
            queryGetter = //here we need to return first instance of class which implements category (parameter either PortalCorp or Portal365) and Oracle
        }
        else if (DDLTool.isMSSQL())
        {
            queryGetter = //here we need to return first instance of class which implements category (parameter either PortalCorp or Portal365) and MsSql

        }
        else if (DDLTool.isPostgres())
        {
            queryGetter = //here we need to return first instance of class which implements category (parameter either PortalCorp or Portal365) and PostgreSql
        }

        return queryGetter

}
def T getImpl(类别)
{
类别查询器
if(DDLTool.isOracle())
{
queryGetter=//这里我们需要返回实现category(参数PortalCorp或Portal365)和Oracle的类的第一个实例
}
else if(DDLTool.isMSSQL())
{
queryGetter=//这里我们需要返回实现category(参数PortalCorp或Portal365)和MsSql的类的第一个实例
}
else if(DDLTool.isPostgres())
{
queryGetter=//这里我们需要返回实现category(参数PortalCorp或Portal365)和PostgreSql的类的第一个实例
}
回程查询器
}
最好的方法是什么?提前谢谢

def <T extends Category> T getImpl(Class<T> category)
{
        Category queryGetter

        if (DDLTool.isOracle())
        {
            queryGetter = //here we need to return first instance of class which implements category (parameter either PortalCorp or Portal365) and Oracle
        }
        else if (DDLTool.isMSSQL())
        {
            queryGetter = //here we need to return first instance of class which implements category (parameter either PortalCorp or Portal365) and MsSql

        }
        else if (DDLTool.isPostgres())
        {
            queryGetter = //here we need to return first instance of class which implements category (parameter either PortalCorp or Portal365) and PostgreSql
        }

        return queryGetter

}