a class castexception problem

Hi, i d like to do the following cast, but i got classcastexception.

String[] toks ={"a","b"{};

String[] pos =(String[]) tagger.tag(Arrays.asList(toks)).toArray();

// tagger.tag returns Object[]

Complier doesnt complain anything. How should I do this casting correctly please?

Thanks!

[481 byte] By [zqzuka] at [2007-11-26 21:26:34]
# 1

if tagger.tag returns Object[] you can't expect the return value to be casted correctly to String[] , can you ?

By the way: Are you sure the following line in your source compiles correctly

String[] toks = {"a","b"{};

g_magossa at 2007-7-10 3:07:17 > top of Java-index,Java Essentials,New To Java...
# 2

> Hi, i d like to do the following cast, but i got

> classcastexception.

>

> > String[] toks = {"a","b"{};

> String[] pos =(String[])

> tagger.tag(Arrays.asList(toks)).toArray();

>

> // tagger.tag returns Object[]

>

>

>

> Complier doesnt complain anything. How should I do

> this casting correctly please?

>

> Thanks!

String[] pos =(String[]) tagger.tag(Arrays.asList(toks)).toArray(new String[0]);

warnerjaa at 2007-7-10 3:07:17 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks alot! It has been solved!
zqzuka at 2007-7-10 3:07:17 > top of Java-index,Java Essentials,New To Java...