Subclassing HashMap in Scala, working around type erasure?

Note that while case s: SomeT Doesn't work because Some s type parameter is erased, this is different: case s @ Some(_: T) In this case, it doesn't work because T is a type parameter itself. While this does not make a difference in your case (no, there's no way other than manifests), consider the following: case s: SomeInt // erased case s @ Some(_: Int) // not erased.

Note that while case s: SomeT Doesn't work because Some's type parameter is erased, this is different: case s @ Some(_: T) In this case, it doesn't work because T is a type parameter itself. While this does not make a difference in your case (no, there's no way other than manifests), consider the following: case s: SomeInt // erased case s @ Some(_: Int) // not erased.

I have not come across that yet. – ConnorDoyle Aug 28 at 4:25 what would case Some(_ : T) do? – Raphael Aug 28 at 13:05 @ConnorDoyle Check this question.

– Daniel C. Sobral Aug 29 at 19:02 1 @Raphael It will verify that the value can be extracted with Some. Unapply (or Some.

UnapplySeq, if it existed), and, if so, check the class of the extracted value against T. If T is erased, it will just compare it against Object, which is always true (even AnyVal subtypes get boxed). – Daniel C.

Sobral Aug 29 at 19:04 Thanks. I think this is curious: type parameter is not erased if the matched expression is assigned a name, but is if not. – Raphael Aug 30 at 8:26.

Let's say that for some good reason I want a generic HashMap that contains all types of objects. I also want to push any unsightly instanceof-like type checks into the data structure. To this end, a method like getAsT This is unfortunate, since the entire purpose of that statement if to check the type!

In this case, do I have an option other than resorting to the experimental Manifest features? Moreover, is there a better basic approach to accomplish this? I got this working with using Manifests.

I was helped along greatly by this article on Stackoverflow. However, I am still curious if there is a cleaner way anyone can recommend.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions