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*

5
  • The problem with this is that the consumer must then pass the class as a parameter, which would be redundant. I'm trying to make a collection that works like ArrayList. Commented Aug 28, 2012 at 20:53
  • Redundant? I really don't think so. Commented Aug 28, 2012 at 21:04
  • You don't think that it is redundant to have to enter the class twice in the constructor? DRY my friend, DRY. Commented Aug 29, 2012 at 3:40
  • @mtmurdock use a factory method and let the compiler infer the generic type parameter. Commented Aug 29, 2012 at 3:54
  • You cannot get the class of a generic type at runtime, which means you still have to enter the class information twice at some point. Yes, your solution is functional, but you'll notice that none of the built in classes do it that way ie: ArrayList Commented Aug 29, 2012 at 4:08