Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance, Java Generics

Tags:

java

c#

generics

Does Generics in Java give any performans advantage over collections.

For example in C# there is a performance advantage as it helps to avoid boxing/unboxing, but as I understand in Java there is no "idea" of generics at byte code level, so after compilation it has the same byte code as for collections.

So is it right to say that there is no performance advantage?

like image 850
NDeveloper Avatar asked May 17 '11 17:05

NDeveloper


1 Answers

I think this link can be very helpful .

Comparing Java and C# Generics

As you have said in C# performance will benefit as Generics helps you to avoid boxing/unboxing. In depth the reason is that .NET generics support value types but Java generics don't work with the primitive types and that is why it can't remove the overhead of boxing/unboxing.

But still you have compile time type checking and no need of explicit casts in your code.

like image 103
Incognito Avatar answered Oct 17 '22 08:10

Incognito