i have linkedhashmap
of pages, , have array of pageids
. want write method returns array of pages whos id found in pageids
the problem page generic class.
when write page<byte[]>[] pagestoreturn = new page<byte[]>[pageids.length];
ofcourse error "cannot create generic array of page".
when try create array , cast it, such: page<byte[]>[] pagestoreturn = (page<byte[]>[]) new page[pageids.length];
warning "type safety: unchecked cast page[] page[]".
i know of delicate issue, have adhere signature of method public page<byte[]>[] getpages(long[] pageids)
, has return array of pages whos generic type array of bytes.
is there workaround issue not include warning supression?
is there workaround issue not include warning supression?
there isn't. but, if everywhere else in program paid attention type safety, , therefore array of page
guaranteed contain instances of page<byte[]>
, cast safe.
the best way handle situation suppress warning, , add comment explaining cast safe, because know elements guaranteed correct type.
Comments
Post a Comment