Skip to content

Commit d129ec0

Browse files
committed
add Q about Int erasing to Object in type parameters
1 parent 836fa13 commit d129ec0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

_overviews/FAQ/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ see the [Scala Collections Guide](https://docs.scala-lang.org/overviews/collecti
8181

8282
[answer on Stack Overflow](https://stackoverflow.com/a/5598107)
8383

84+
### Why do primitive type parameters erase to `Object`?
85+
86+
So for example, a `List[Int]` in Scala code will appear to Java as a
87+
`List[Object]`. The Java type system doesn't allow primitive types to
88+
appear as type parameters, but couldn't they appear as their boxed
89+
equivalents, such as `List[java.lang.Integer]`?
90+
91+
One would hope so, but doing it that way was tried and it proved
92+
impossible. [This SO question](https://stackoverflow.com/questions/11167430/why-are-primitive-types-such-as-int-erased-to-object-in-scala)
93+
sadly lacks a concise explanation, but it does link to past discussions.
94+
8495
## More questions
8596

8697
{% assign overviews = site.overviews | sort: 'num' %}

0 commit comments

Comments
 (0)