[英]How can I convert a Composite ID stored in a MongoDB into a Morphia Java entity object?
[英]How can I convert Entity to Object in java
我定義了一個可以添加任何類型元素的常規List,定義為: List<List<Object>> rows = new ArrayList<>()
; 但是當我從服務層獲取列表時,編譯過程將引發不兼容的類型異常,代碼示例如下:
List<List<Object>> rows = new ArrayList<>();
List<ProductEntity> result = searchResponse.getProducts();
rows.add(result);
例外是: incompatible types: java.util.List<com.shopee.data.webapispec.brandseller.entity.product.ProductEntity> cannot be converted to java.util.List<java.lang.Object>
運行命令時, incompatible types: java.util.List<com.shopee.data.webapispec.brandseller.entity.product.ProductEntity> cannot be converted to java.util.List<java.lang.Object>
“ mvn clean install
”,有人知道如何處理嗎?
ProductEntity
是Object
的子類。 但是List<ProductEntity>
不是List<Object>
的子類。
您需要List<List<? extends Object>> rows = new ArrayList<>();
List<List<? extends Object>> rows = new ArrayList<>();
使這項工作。
有關泛型和對象層次結構的詳細信息,請參見此處
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.