2012-11-07 46 views
0

獲得的價值從下面的線,我得到的PdsLongAttrImpl如何從一個對象

Object obj = typeInfo.getParseMethod().invoke(null, rawValue); 

一個對象,該對象具有propertyKeyValue的領域。

如何從特定的上述對象中獲取值?

回答

2

obj鍵入回報。

例如,如果你的預期收益類型爲PdsLongAttrImpl

然後,這將是:

PdsLongAttrImpl pdsObj = (PdsLongAttrImpl)obj; 

//然後在pdsObj進行操作。

注意:如果obj爲你鑄造型的沒有,你將最終ClassCastException

0

如果你知道什麼類型的對象(這PdsAttrImpl是可見的類代碼),你可以施放它像

PdsLongAttrImpl casted = (PdsLongAttrImpl)obj; 

//assuming you have getXXX methods for the two fields 

casted.getPropertyKey(); 
casted.getValue(); 
1

只需將值轉換成正確的類型:

YourTypeHere obj = (YourTypeHere)typeInfo.getParseMethod().invoke(null, rawValue); 

如果你不能確定的類型,你可以使用:

System.out.println(typeInfo.getParseMethod().invoke(null, rawValue).getClass().getName)); 

這將打印類的名稱在控制檯上