You can only do CASTing between super class and sub class, if you really need to transport this "List" to a "DataSet" you need to have an adapter pattern, but still, it's not a "casting" per se
节是
【在 t*******t 的大作中提到】 : Dataset ds = (Dataset) new GctParser().parse(); : Gctparser.parse()返回的是一个List,而Dataset是一个interface,这种转换的细节是 : 在什么地方写出来的啊? : 多谢!google了type conversion,结果是讲 int -》double。
r*y
5 楼
写完了咩?
【在 c**r 的大作中提到】 : 嗯,这个系列还不错。
g*g
6 楼
List也是一个interface,Dataset既然是Interface, 你可以查Dataset源码,多半extends List
节是
【在 t*******t 的大作中提到】 : Dataset ds = (Dataset) new GctParser().parse(); : Gctparser.parse()返回的是一个List,而Dataset是一个interface,这种转换的细节是 : 在什么地方写出来的啊? : 多谢!google了type conversion,结果是讲 int -》double。
c*r
7 楼
它是一个一个的系列小故事,每个都是很独立的,也没看到啥主线, 所以可以说完了好些个故事了。
【在 r******y 的大作中提到】 : 写完了咩?
t*t
8 楼
恍然大悟。。。
【在 w*******o 的大作中提到】 : You can only do CASTing between super class and sub class, : if you really need to transport this "List" to a "DataSet" : you need to have an adapter pattern, but still, it's not : a "casting" per se : : 节是
Dataset extends PersistentObject(an interface, written by the author) PersistenObject extends Serializable i am really confused now.. i guess tomorrow i will follow this clue. thanks!
Being a List doesn't prevent a class from implementing Dataset. A class can implement multiple interfaces.
thanks!
【在 t*******t 的大作中提到】 : Dataset extends PersistentObject(an interface, written by the author) : PersistenObject extends Serializable : i am really confused now.. i guess tomorrow i will follow this clue. thanks!
o*1
12 楼
yes, 楼主好像把extends 和 implements 搞混了。
can
【在 F****n 的大作中提到】 : Being a List doesn't prevent a class from implementing Dataset. A class can : implement multiple interfaces. : : thanks!
cast到 imple subinterfa No way, Dataset has _got_ to either extend or implement List for the casting to work. Is this some open source software? Can you point us to the source code?
hi. thank you for your information i have attached the source codes.
【在 m******t 的大作中提到】 : : cast到 : imple : subinterfa : No way, Dataset has _got_ to either extend or implement List for : the casting to work. : Is this some open source software? Can you point us to the source code?
A*o
20 楼
read your source code, it's not what you said. it's actually returned you an object. Dataset ds = (Dataset) new GctParser().parse().get(0); the parse() does give you a List but the get gives you an Object before being casted... No surprises. Over and out.
节是
【在 t*******t 的大作中提到】 : Dataset ds = (Dataset) new GctParser().parse(); : Gctparser.parse()返回的是一个List,而Dataset是一个interface,这种转换的细节是 : 在什么地方写出来的啊? : 多谢!google了type conversion,结果是讲 int -》double。
m*t
21 楼
Good catch. I missed that in my "no way" statement. Now that could be a rather tricky (not necessarily good) interview question. 8-)
【在 c*****t 的大作中提到】 : 给你个例子: : class A implements Dataset, List { } : 写 code 的人知道那个 parse 返回的是什么 class 。不过这不是好的写法。 : : cast到 : imple : subinterfa : extends一
A*o
22 楼
well, the actually case was rather straight forward. :p
【在 m******t 的大作中提到】 : : Good catch. I missed that in my "no way" statement. : Now that could be a rather tricky (not necessarily good) : interview question. 8-)
t*t
23 楼
thanks! Following you clue, I finally figured out the reason: the parse() returns: return unmodlist(new PersistentObject[]{ds}); ds is of the type Dataset, which is an interface that extends PersistentObje ct. But i am curious why the author put it this way. actually the source code for unmodlist is: /** * Utility method to place specified pobs in an unmodifiable list */ protected static List unmodlist(PersistentObject[] pobs) { List list = new ArrayList(pobs.length);
【在 A**o 的大作中提到】 : read your source code, : it's not what you said. it's actually returned you an object. : Dataset ds = (Dataset) new GctParser().parse().get(0); : the parse() does give you a List : but the get gives you an Object before being casted... : No surprises. Over and out. : : 节是
m*t
24 楼
a These days I always make my classes Serializable by default, unless it's clearly not serializable, or doesn't make sense to be. You never know when they might be sent over wire. That said, I don't necessarily agree with making them all extend the same base class...
【在 t*******t 的大作中提到】 : thanks! : Following you clue, I finally figured out the reason: : the parse() returns: : return unmodlist(new PersistentObject[]{ds}); : ds is of the type Dataset, which is an interface that extends PersistentObje : ct. : But i am curious why the author put it this way. : actually the source code for unmodlist is: : /** : * Utility method to place specified pobs in an unmodifiable list
t*t
25 楼
I just googled "send over wire", it looks like serialization benefits RMI. The src code i provided is actually for a client/server model application. S o, the serialization is an essential part for this network application. Is t his correct? thanks
【在 m******t 的大作中提到】 : : a : These days I always make my classes Serializable by default, unless it's : clearly : not serializable, or doesn't make sense to be. You never know when they : might : be sent over wire. : That said, I don't necessarily agree with making them all extend the same : base class...
m*t
26 楼
Most of the network transportation mechanisms used in Java, including RMI, require objects to be serializable to begin with. Serializable objects can also be easily persisted into byte streams, which is useful for example when replicating http sessions. S t Right. The author must have some stronger reason to have a base class though .
【在 t*******t 的大作中提到】 : I just googled "send over wire", it looks like serialization benefits RMI. : The src code i provided is actually for a client/server model application. S : o, the serialization is an essential part for this network application. Is t : his correct? : thanks