[英]Why does my Java code return a memory address and not a string?
我正在從PlaneXML調用WSDL服務-API參考在這里https://flightwise.com/documentation/39/PlaneXML_API_Reference.html#AirportInfo
我的代碼:
public static void airportName() throws RemoteException{
String lax = "LAX";
PlaneXMLv1SoapProxy foo = new PlaneXMLv1SoapProxy();
Airport [] info = foo.airportInfo(lax);
System.out.println("output 1: " + info);
System.out.println("output 2: " + info.toString());
System.out.println("output 3: " + info[0]);
}
我的輸出:
output 1: [Lcom.flightwise.planexml.ws.Airport;@604ed9f0
output 2: [Lcom.flightwise.planexml.ws.Airport;@604ed9f0
test
test
output 3: com.flightwise.planexml.ws.Airport@9117a1a4
為什么返回這些內存地址而不是字符串? 有什么想法可能導致“測試”輸出嗎?
謝謝
正如其他人回答的那樣,您是:
1-打印陣列本身。
2-使用toString()而沒有覆蓋。
3-打印機場對象。
如果要打印有關Airport的特定內容,則需要顯式使用屬性。 另外,請閱讀文檔https://flightwise.com/documentation/39/PlaneXML_API_Reference.html#Airport
內容為:
提供有關機場的基本信息。
字符串相同
國際民航組織作為字符串
位置作為字符串
倍增
龍作為雙
提升為Int32
GMTOffset為Short
DST短
如果實現Airport
對象的toString()
方法,則可以在控制台上看到字符串。
toString()不返回地址。 它返回
getClass().getName() + '@' + Integer.toHexString(hashCode())
由於info
是String
的數組,因此輸出是[Lcom.flightwise.planexml.ws.Airport;@604ed9f0
而不是String
,為什么要輸出toString()
(如果已覆蓋)方法的原因Airport
課,那就去做:
System.out.println(info[0].toString()) // you can use any index in place of 0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.