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

1

u/kprotty May 22 '20

Zig supports reified types at compile time, but not at runtime: https://ziglang.org/documentation/master/#typeInfo.

This would be the zig equivalent. The result would be known at compile time instead of runtime. object: var is essentially a generic for "any" type. Since Zig is a natively compiled language like C and doesn't support inheritance, this means that nothing is auto-boxed into objects and instanceof doesn't exist by default. Both of them could be implemented manually if the programmer wanted to though:

fn compare(comptime Q: type, object: var) bool {
  return @TypeOf(object) == Q;
}