Earlier quoted context omitted.
Can you have a collection of primitives?
No, but yes. There is nothing in the standard library, that implements the Collection-interface and works with primitives. However you can write your own and there are several implementations of collections for primitives. The problem is that you have to implement them seperately for each type of primitive (e.g. an IntList, DoubleList, BooleanList...).
Rating 26 years of Java changes
321–327 of 327 posts
Re: Rating 26 years of Java changes
#322Earlier quoted context omitted.
No, but yes. There is nothing in the standard library, that implements the Collection-interface and works with primitives. However you can write your own and there are several implementations of collections for primitives. The problem is that you have to implement them seperately for each type of primitive (e.g. an IntList, DoubleList, BooleanList...).
Can't you use templates for that, or do these also only work with objects?
Re: Rating 26 years of Java changes
#323Earlier quoted context omitted.
Can't you use templates for that, or do these also only work with objects?
Templates do not exist in Java.
Re: Rating 26 years of Java changes
#324Earlier quoted context omitted.
Maven was peak Java build tool. I detest Gradle. Some people just hate XML enough to doom us all.
Can't speak for everyone, but I think a substantial part of the shift from Maven to Gradle was the ability to write build scripts: you didn't need to write a plugin. I'm hoping that Maven (and Gradle) can take advantage of JEPs 458 and 512 to allow people to write build scripts for that Java projects in Java. - https://openjdk.org/jeps/458 - https://openjdk.org/jeps/512
Maven's requirement that you write plugins meant that you had to have a decent understanding of the conventions that Maven brought to the table before you could inflict some monster on the world.
In Gradle you can do something quick to get your idea working how ever terrible it is and however much it defies convention or breaks the expectations of anyone coming to the project later on.
Re: Rating 26 years of Java changes
#325Earlier quoted context omitted.
Templates do not exist in Java.
My bad, I think they are called Generics in Java. I always thought of these as the same thing, just with different names in different languages, is that wrong?
Java uses Type Erasure for Generics, which means that generic type variables are checked at compile time, but that type information is not available at runtime. At compile time you may have List and List but at runtime its all just List (Object being the base type everything inherits from). Basically List stores a bunch of pointers to objects and since pointers can point to anything a List can basically "store" anything.
Then you have a divide between primitives and Objects in Java, where primitives are double, int, boolean etc.. Primitives are types in the C-sense, e.g. int is nothing more than a 32-bit number, not a class in the Java-sense. But since ints are not classes and as such do not inherit from Object, they cannot be placed inside of List. Therefore there cannot be a List. But there is Integer, which is an Object-wrapper around an int, meaning you can have a List. This is called boxing and like all indirection carries a performance penalty.
Java hopes to heal this rift between primitives and Objects through something called Project Valhalla which has been 10 years in the making and is expected to land in the next two years or so.
Hope this ramble is comprehensible.
Re: Rating 26 years of Java changes
#326Earlier quoted context omitted.
My bad, I think they are called Generics in Java. I always thought of these as the same thing, just with different names in different languages, is that wrong?
Templates and generics are very different. Afaik Templates generate specialised code for each invocation of that template with a different type. Java uses Type Erasure for Generics, which means that generic type variables are checked at compile time, but that type information is not available at runtime. At compile time you may have List and List but at runtime its all just List (Object being the base type everything…
Re: Rating 26 years of Java changes
#327Earlier quoted context omitted.
Templates and generics are very different. Afaik Templates generate specialised code for each invocation of that template with a different type. Java uses Type Erasure for Generics, which means that generic type variables are checked at compile time, but that type information is not available at runtime. At compile time you may have List and List but at runtime its all just List (Object being the base type everything…
Thanks it is. So the compiler would bark on List ?