soabase / soabase-halva

Idiomatic Scala ... in Java
https://github.com/soabase/soabase-halva/blob/master/README.md
Apache License 2.0
81 stars 5 forks source link

add a factory method for AnyType #30

Closed smilingleo closed 8 years ago

smilingleo commented 8 years ago

instead of new AnyType<MyType>(){} everywhere, just use Any.type()

Randgalt commented 8 years ago

Wow - I'm surprised that works. I thought that the only way to get the semi-reified type was the way I did it. I'll need to test this in some edge cases.

Randgalt commented 8 years ago

This does not work. Try this:

Any<List<String>> anyList1 = Any.type();
Any<List<String>> anyList2 = new Any<List<String>>(){};
System.out.println(anyList1.getRawType());
System.out.println(anyList2.getRawType());

There's no workaround that I know of.

smilingleo commented 8 years ago

Oops, poor Java type system. Let me see if there I can find a workaround.

Randgalt commented 8 years ago

It's erasure. A 1000 deaths for those who decided erasure was OK.

smilingleo commented 8 years ago

no workaround, :(

Randgalt commented 8 years ago

There's a special place in Hell for erasure :(