Chubigans
02-16-2010, 04:48 PM
edit: I originally had a post about getting information about my generics. That's no longer the case. I've looked up type erasure and I understand it.
My question is, how do you get around type erasure?
For example, if I have an object Tile<M,A> which contains a mediumObject and an actorObject.
I want to create a method getObject<T> that returns the mediumObject if T is the same type as M, and actorObject if A is the same type as T.
If anyone can think of a way to do this, let me know. The point is I want to use generics because I'd like to have one method for getting ALL my objects instead of separate methods for everything, which looks dirty.
My question is, how do you get around type erasure?
For example, if I have an object Tile<M,A> which contains a mediumObject and an actorObject.
I want to create a method getObject<T> that returns the mediumObject if T is the same type as M, and actorObject if A is the same type as T.
If anyone can think of a way to do this, let me know. The point is I want to use generics because I'd like to have one method for getting ALL my objects instead of separate methods for everything, which looks dirty.