Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • But (E[]) will not convert into (O[]) by the type erasure? Commented Sep 2, 2013 at 21:53
  • @user2693979 It will. Generics are compiler tool not runtime. I don't quite get what problem you are trying to show... Commented Sep 2, 2013 at 22:02
  • @user2693979 You should accept Rohit`s answer if you consider it better. No pressure only because I posted mine little earlier. Commented Sep 2, 2013 at 22:17
  • But if E[] will be Object[] and (E[]) will be (Object[]), then why is difference between (e = new E[10]) and (e = (E[]) Object[10])? Will not both be e = new Object[10]? Commented Sep 2, 2013 at 22:20
  • @user2693979 I suspect that new E[size] is not allowed to prevent thinking that we are actually creating array of E type and not Object type. Ways I mentioned in my answer clearly shows what is going on, while new E[size] can be interpreted incorrectly. But again, that is only my suspicions. Commented Sep 2, 2013 at 22:28