What is the concept of erasure in generics in Java?

前端 未结 8 682
误落风尘
误落风尘 2020-11-22 01:45

What is the concept of erasure in generics in Java?

8条回答
  •  被撕碎了的回忆
    2020-11-22 01:58

    As I understand it (being a .NET guy) the JVM has no concept of generics, so the compiler replaces type parameters with Object and performs all the casting for you.

    This means that Java generics are nothing but syntax sugar and don't offer any performance improvement for value types that require boxing/unboxing when passed by reference.

提交回复
热议问题