6 ms·
I think the way Rust took with Generics should be the next step for Java, it for sure can boost the Java apps performance. In Rust you have both types erasure a
by gkorland 6y ago
I think the way Rust took with Generics should be the next step for Java, it for sure can boost the Java apps performance. In Rust you have both types erasure and C++ style templates which don't erasure the types.
- dep_b 6y agoThere is no next step for Java, because of backwards compatibility this is as good as it gets.
- Felk 6y agoWhile it does need to maintain backwards compatibility, Project Valhalla seems promising on improving on some of Java Generic's pain points. So it's not a dead end quite yet
- kaba0 6y agoI don’t think templates are wanted, but with the coming of unification of primitive and reference types, Java could get a huge speedup in performance.
- henryjcee 6y agoThis has passed me by, what's happening?
- BenoitP 6y agoNot so much a unification, as the new constructs sort of enhance and retrofit current primitives types. These new primitives are "class instances that lack object identity and can be stored and passed directly, without object headers or indirections". It will allow (almost) direct control over data layout. At least make it so that it is cache/prefetch/SIMD friendly. Here is the JEP: https://openjdk.java.net/jeps/401 https://openjdk.java.net/jeps/401
- mrkeen 6y ago> the way Rust took with Generics should be the next step for Java I have a List<Integer>. Maybe I want to replace List with something else, call it L. Can I write L<Integer> in Java? No. Rust? No. C#? No Kotlin? No. Does Go have generics yet? Once it does, I'm sure it'll be a No as well. Haskell and Scala got it right.
- riffraff 6y agoI don't understand what you're saying, what is the problem with L<Integer> ?
- mrkeen 6y agoThere shouldn't be a problem with it! <L> void process(final L<Integer> input) { } ------------------------------------------ <L> void process(final L<Integer> input) { ^ required: class found: type parameter L where L is a type-variable: L extends Object declared in method <L>process(<any>)
- p2t2p 6y agoWorks perfectly: public <T extends Collection<Integer>> T process(T collectionOfInteger) { return collectionOfInteger; }
- petersellers 6y agoWhat if your "T" isn't a collection though?
- Joker_vD 6y agoThen what can you really do with it except of returning it back as-is?
- throw149102 6y ago
- kasperni 6y agoA Parametric VM [1] is part of Java's project Valhalla. However, it is currently some releases away. [1] https://cr.openjdk.java.net/~jrose/values/parametric-vm.pdf https://cr.openjdk.java.net/~jrose/values/parametric-vm.pdf
- _old_dude_ 6y agoVery cool, it seems to be the best of both worlds, the specialization of the class/fields is done the first time a specialized type is instantiated while the specialization of methods is done by the JIT. And the VM can specialize on any values, not just types.