Questions tagged [erasure]

When implementing generics in a programming language often the binary does not contain any of the type information from the generics. This is referred to as "erasure"

Java is famous (and often criticized) for using erasure. This choice was made to keep the language compatible with older versions which was always an important design goal for java first by Sun and later by Oracle.

Other similar languages like C# keep the type information from generics which allows to use this information at runtime.

Scala which compiles to Java byte code also has to use erasure, but uses other language features like Manifests to solve the problem of missing type information at runtime at least to some extend.

The tag should be used for question regarding the way erasure works and problems arising from erasure.

82 questions
0
votes
1 answer

gcnew and secure erasure

I have memory that I have to allocate with gcnew (C++, passing the memory to managed code), which will contain secure information (passwords, HIPAA data, etc.). I realize that such memory is garbage collected, and that implies that I don't control…
0
votes
2 answers

Scala collect type pattern and type erasure

Let val a = List ("a", 1, 2.34, "b", List(6,7)) a: List[Any] = List(a, 1, 2.34, b, List(6, 7)) and so a.collect { case s: String => s } res: List[String] = List(a, b) However a.collect { case s: List[Int] => s } warns that non-variable type…
elm
  • 20,117
  • 14
  • 67
  • 113
0
votes
2 answers

Method matches interface prototype, but won't override

I have the following code: public interface StackInterface { public T pop(); public void push(T n); } public class myStack implements StackInterface> { Node head; Node next; Node tail; public myStack(T t) { …
Dax Duisado
  • 197
  • 2
  • 11
0
votes
1 answer

Get reified type of symbol after the erasure phase of the Scala 2.9.3 compiler

I'm writing a compiler plugin that translates a subset of Scala to C++ (ignore the apparent insanity of this task). I'm using a number of plugins that must run after the erasure phase. However, I require the full type information to output valid…
Peter Sutton
  • 1,145
  • 7
  • 20
0
votes
1 answer

Java - Collection of abstract class, children contain disparate objects - Any "good" way to handle these wrapped objects?

Let's say we have something like this: public abstract class MyClass { //Stuff in here } public class MyClassA extends MyClass { private String thingie; //Along with getter/setters, of course //Other stuff } public class MyClassB…
user1017413
  • 2,023
  • 4
  • 26
  • 41
0
votes
0 answers

What are the benefits of contravariance in JAVA

I'd like to ask what are the benefits of using contravariance in JAVA? Assume that we have two methods: public static void f1(List list, T item){ list.add(item); } public static void f2(List list, T…
Iza Marek
  • 251
  • 1
  • 6
-1
votes
1 answer

Pattern Matching on `Any` as 2-tuple?

Given the following function: scala> def foo(x: Any) = x match { | case _: (String, Int) => "foo" | case _ => "bar" | } I get the following compile-time warning: :8: warning: non-variable type argument…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
1 2 3 4 5
6