![](/img/trans.png)
[英]Can I have a class field that is the Class<?> of a type that must extend another class and an interface?
[英]Can I have a field in a @Document that is of the Class type?
我想將文檔保留到MongoDB。 我正在使用Spring-Data-MongoDB聲明@Document
。 有一個特定的文件給我帶來了問題。 下面是一個有問題的文檔示例,該文檔的字段類型為java.lang.Class
。
@Document
public class Value {
@Id
private Class<? extends I> clazz;
private Integer value;
...
}
我得到的錯誤如下。
Caused by: java.lang.SecurityException: Can not make a java.lang.Class constructor accessible
我當前的解決方案是使用String
而不是Class
。 對於解決不使用Class
類型字段的問題,我將不勝感激。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.