简体   繁体   English

使用泛型和ActiveJDBC模型

[英]Working with generics and ActiveJDBC Models

I am trying to convert a list of records to some Java object (so, ActiveJDBC Model to another Java class), but I want to be able to call the same method for all my models and pass the Model type, something like: 我正在尝试将记录列表转换为某个Java对象(因此,将ActiveJDBC Model转换为另一个Java类),但是我希望能够为我所有的模型调用相同的方法并传递Model类型,例如:

private <M extends Model, T> List<T> getObjects(Class<M> modelType, Class<T> objectType) {
    List<T> records = new ArrayList<T>();
    M.findWith(new ModelListener<M>() {
        public void onModel(M row) {
            // Here I would convert the Model to my desired object and add it to the list of records
        }
    }, null);
    return records.isEmpty() ? null : records;
}

Which I would call like: 我会这样称呼:

getObjects(MyModel.class, MyObject.class);

I get 我懂了

Exception: failed to determine Model class name, are you sure models have been instrumented?

on M.findWith(...) M.findWith(...)

Any idea how to make it work? 任何想法如何使其工作?

Thanks! 谢谢!

you need to instrument models before you use them. 您需要先对模型进行测量,然后再使用它们。 Please, see http://javalite.io/instrumentation 请参阅http://javalite.io/instrumentation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM