guness
guness

Reputation: 6656

How to overcome type safety warning without ignoring it in eclipse?

I am getting warning from eclipse

Type safety: The expression of type TreeItem[] needs unchecked conversion to conform to TreeItem<AppleItem>[]

while using this:

TreeItem<AppleItem>[] friends = item.getChildren().toArray(new TreeItem[0]);

I dont want to use @uncheck or I dont want to use a loop for inserting one by one. Is there a way to do this?

Appearantly getChildren returns an ArrayList like ArrayList<TreeItem<AppleItem>>

Thanks in advance.

Upvotes: 0

Views: 419

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198211

Nope, there's no way to do it without an unchecked cast. @Ivaylo's solution won't save you from casting, either.

Upvotes: 1

Related Questions