Tag Info

New answers tagged

2

In a nutshell, Scala can do it because the Scala compiler is a master in code transformation/generation. Which means Java could do it too (maybe it does already). The trick is not made at the bytecode level but at the source level. Could you guess the output of this code: def test[T](f : => Any) : T = { try { val x = f.asInstanceOf[T] ...


2

Reified generics do not require JVM support. Yes, they would be easier and most performant with JVM support, but JVM support is not necessary. For instance, a Scala compiler could, for every class featuring a type variable, add a field that stores the corresponding object: class List<T> { } void test() { List<?> list = new ...


11

To address the specific issue that you raise, of reified generics . . . In many contexts, type parameters are actually saved in class-files and exploitable via reflection, even despite erasure. For example, the following program prints class java.lang.String: import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import ...


7

JVM bytecode pretends to be a kind of generic machine code, and it is indeed, so... what makes you think it couldn't support any other language? JVM bytecode is a Turing complete language, and thus, every program, no matter in which language is written, can be compiled/translated into bytecode. There are a lot of languages which already have a bytecode ...


27

"All" programming languages run on x86, so how can they be much different from each other? Brainfuck and Haskell are both Turing complete, so they can both do the exact same tasks. There's a bit of room for syntax changes, syntax sugar and compiler magic in between. You can do quite a lot in there, but there is always a limit. In your case, it's JVM byte ...



Top 50 recent answers are included