Backwards compatibility is an important asset (for Java), but the downside of type erasure is (among others) that in case of primitive types autoboxing is used extensively which causes developers to favor non-generic classes over generic ones (for performance reasons; autoboxing is quite slow).
Now, Scala 2.8 has a solution for this, and that's a new annotation called @specialized.
class MyCollection [@specialized A]{ def simplyReturn(x: A): A = { x } }
What it does is it causes the compiler to generate specialized versions for primitives, so that autoboxing does not have to occur, which is faster. I should investigate the performance difference in future and share the results!
You can also specify which primitive classes should be specialized.
class MyCollection [@specialized("Int") A]{ def simplyReturn(x: A): A = { x } }
Read more about it in the official Scala document (PDF).
Scala 2.8 Showcase
- Scala 2.8 Showcase - Collections
- Scala 2.8 Showcase - Arrays
- Scala 2.8 Showcase - Type Specialization
It is really a great work and the way in which u r sharing the knowledge is excellent
ReplyDeleteTally Course in Tambaram
Tally Course in Anna Nagar
Tally Course in Velachery
Tally Course in T Nagar
Tally Course in Porur
Tally Course in OMR
Tally course in Chennai
ReplyDeleteAwesome Blog!!! Thanks for it, it is more useful for us.
IELTS Coaching in Tambaram
IELTS Coaching in anna nagar
IELTS Coaching in Velachery
IELTS Coaching in OMR
IELTS Coaching in Chennai
Thanks for providing wonderful information with us. Thank you so much.
ReplyDeleteGerman Coaching
Python Coaching
Software Testing Training in OMR
When I was little, I always imagined and dreamed that I would be able to write a resume perfectly, but it didn’t work out, although I found this site https://paulbender.gumroad.com/p/what-did-you-forget-to-add-to-your-resume, it is about writing a resume and other services
ReplyDelete