r/programming • • May 21 '20

Java programming language celebrates 25 years

https://www.infoworld.com/article/3544229/java-programming-language-celebrates-25-years.html
95 Upvotes

73 comments sorted by

View all comments

Show parent comments

0

u/[deleted] May 21 '20

[deleted]

4

u/Ayfid May 21 '20

Generics are still shit today in Java.

3

u/DetriusXii May 21 '20

Could you explain why they're shit in Java?

3

u/florinp May 21 '20

Type erasure at runtime for a language that use parametric polymorphism with runtime support

6

u/DetriusXii May 21 '20

Type erasure at runtime for a language that use parametric polymorphism with runtime support

Haskell has type erasure too. It seems that most languages that want to implement higher kinded types needs to have type erasure. There are no languages with reified types and with higher kinded types.

2

u/flatfinger May 21 '20

What do you mean "higher kinded types"? The .NET framework, and languages targeting it, use reified generics but also support covariant and contravariant generic interfaces.

2

u/DetriusXii May 21 '20

Higher kinded types are generic types that can box other types. Haskell and Scala support higher kinded types whereas .NET only support concrete types. Instead of only being able to pass a function void doSomething<A>(List<A> list) into a function, in Haskell and Scala, a function can be declared as void doSomething<M<_>, A>(M<A> list) where M can be any type of container, including a List<_>.

1

u/kprotty May 21 '20

If I understand that definition of HKT correctly, then could Ziglang be considered as one with reified generics without type erasure?

fn doSomething(comptime M: var, comptime A: type, list: M(A)) void {}

1

u/DetriusXii May 22 '20

If Zig allows that, then you have higher kinded types. I'm not fully sure that zig's types are reified from the examples provided. Are you able to perform a cast of a function parameter into a generic type? C# allows that. Java does not. C# allows bool compare<Q>(object o) { return o instanceof Q; }

→ More replies (0)

1

u/Ayfid May 22 '20 edited May 22 '20

The C# language doesn't allow that, but the runtime can reify such types. You can write code which, at runtime, creates a new realisation of any generic type, and the JIT will reify that and generate all of the relevant code and type metadata. You can then instantiate this new type and call methods on it.

The language does not provide mechanisms to do this, but you can do it with reflection.

Reified generics is not a blocker to type constructors. This functionality is already possible today with reification in the runtime. C# not having it yet is not proof that it is only possible with type erasure.

1

u/florinp May 22 '20

I've said language with parametric polymorphism with runtime support.

Haskell don't need runtime support for that. The same as C++ for example.

Java doesn't have support for higher kinded type so I don't understand your post.