請問java String 點轉做object

2007-04-13 8:28 am
Object item;
String str;
str = ABC;
item要點拎到str呢??

thanks..

回答 (2)

2007-04-13 9:11 am
✔ 最佳答案
first of all:

str = "ABC"; instead of str = ABC;
double quote is used to declear string.

String to Object:
item = str;

Object to String:
item.toString();
2007-04-13 12:33 pm
sorry呀,唔係好明你問乜野,你係咪指點樣響item入面access到str呀?定係點樣將str convert做object type?定係有其他意思?唔係好明你既 "拎到"係咩意思喎,定係你想講 "link到"?

如果你只係想將個 item變做str,你只要up cast object就得架啦,如:

Object item;
String str = " ABC ";
item = (Object) str; // <= 咁樣就可以up cast String type做Object type架啦

我諗你需要知道既係響Java入面,所有non-Primitive types都係object既subclass黎架,所以簡單黎講如果個type唔係byte, short int, long, float, double boolean, char既話,你都可以用up cast既方法變做object架

如果有咩唔明,歡迎再問


收錄日期: 2021-04-25 19:52:16
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070413000051KK00171

檢視 Wayback Machine 備份