Java is not a serious language

Why can't I make ArrayLists of primitive types in Java? Why do I have to go out of my way to use the object wrapper instead?

Beware Cat Shirt $21.68

Rise, Grind, Banana Find Shirt $21.68

Beware Cat Shirt $21.68

  1. 1 month ago
    Anonymous

    because primitives dont implement sortable

    • 1 month ago
      Anonymous

      C# doesn't have this problem. Sounds like a skill issue

      • 1 month ago
        Anonymous

        That's because Microsaars made even the primitive types objects
        Chads++ don't have this problem because we just copy and paste the code for each new type

    • 1 month ago
      Anonymous

      *comparable
      https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#sort-java.util.Comparator-
      you'll note that it clearly says
      >All elements in this list must be mutually comparable using the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the list).

      • 1 month ago
        Anonymous

        Because of type erasure you moron. But it doesn't matter, internally jvm will optimize things so you aren't allocating an entire object to store an int.

        Java only has to compile one version of a generic function since all object pointers are the same size.
        If you've ever used templates in C++, you need the source of the template at compile time in order to use it, which can be really inconvenient if you're trying to write modular code.

        c# doesn't have this problem

      • 1 month ago
        Anonymous

        Missing the mark.
        It's because Java does not have proper value types that can implement interfaces.
        So every single int has to be boxed in an object (hence the Integer class).
        It's archaic and moronic, C# indeed fixed this.

    • 1 month ago
      Anonymous

      *comparable
      https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#sort-java.util.Comparator-
      you'll note that it clearly says
      >All elements in this list must be mutually comparable using the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the list).

      Because of type erasure you moron. But it doesn't matter, internally jvm will optimize things so you aren't allocating an entire object to store an int.

      Java only has to compile one version of a generic function since all object pointers are the same size.
      If you've ever used templates in C++, you need the source of the template at compile time in order to use it, which can be really inconvenient if you're trying to write modular code.

      Skill issue

      good morning sirs

    • 1 month ago
      Anonymous

      Why don't they? Rust implements PartialOrd (the equivalent of comparable) for all of its integer and floating point value types.

      • 1 month ago
        Anonymous

        because primitives were introduced into the lang to be lightweight and could be alocated on stack.

        Kotlin solves this issues btw

  2. 1 month ago
    Anonymous

    Because of type erasure you moron. But it doesn't matter, internally jvm will optimize things so you aren't allocating an entire object to store an int.

    • 1 month ago
      Anonymous

      >proceeds to allocate Integer objects all across the heap

      • 1 month ago
        Anonymous

        >heavily optimizes the allocator and garbage collector for large numbers of short lived objects in your path

    • 1 month ago
      Anonymous

      The reason is that java didn't have generic in the intial versions. They later shoehorned both generics and couldn't find a way to allow it primitives without breaking backward compatibility. Type-erasure in java is also a consequences of this incompetence.

      • 1 month ago
        Anonymous

        Haskell has type erasure also thoubeit

  3. 1 month ago
    Anonymous

    Java only has to compile one version of a generic function since all object pointers are the same size.
    If you've ever used templates in C++, you need the source of the template at compile time in order to use it, which can be really inconvenient if you're trying to write modular code.

  4. 1 month ago
    Anonymous

    Skill issue

  5. 1 month ago
    Anonymous

    I made a nice little dynamic array in C yesterday, and I found it fun.

    • 1 month ago
      Anonymous

      Youtube showed me this a couple of hours ago.

      • 1 month ago
        Anonymous

        Funny, I didn't watch it though. I just tried to learn realloc and that was a good way to do it.
        Plus I saw a thread of the Lua source code and they had a nice dynamic array algorithm

      • 1 month ago
        Anonymous

        I just watched the video and I don't really like how he did it.
        I just went with
        typedef struct {
        size_t s; // total size
        size_t c; // count of elements
        <type> *data;
        } DA_<type>;

        Yes, I could use a void * for the data, but then I need to start casting and recording the data type size and stuff
        The real part of it is the macro to append an item to the array, which works better with a hardcoded datatype cause then it can just sizeof(*DA->data) and be type ambivalent, including structs and shit.

  6. 1 month ago
    Anonymous

    It would be worse if it silently wrapped and unwrapped your ints. At least this way you're aware of how it actually works.

  7. 1 month ago
    Anonymous

    Use Integer object
    ArrayList<Integer>
    primitive data is like C. no object in memory just number.
    Use Integer object. Integer is just like int, but with more capabilities and methods.

    • 1 month ago
      Anonymous

      ok pajeet

    • 1 month ago
      Anonymous

      Sure, at the cost of one GC reference per item. It is dumb to still have no proper value types in 2024. Heil C#.

    • 1 month ago
      Anonymous

      good morning saar

    • 1 month ago
      Anonymous

      Why would I need a number with "capabilities", just let me call a std functionstatic method if I want to do something with it

      • 1 month ago
        Anonymous

        Integer.parseInt(String)
        very useful function.

        [...]
        [...]

        c# doesn't have this problem

        syntactic sugar. very good sir yes

        • 1 month ago
          Anonymous

          >Integer.parseInt(String)
          >very useful function.
          It works like that because Java can't into toplevel functions. C has strtol.

    • 1 month ago
      Anonymous

      >Integer is just like int, but with more capabilities and methods.
      I want people like you to exit the programming job market forever basically

  8. 1 month ago
    Anonymous

    Because generics are just stuff for the typechecker and not stored in Java bytecode. That's the reason why you can't write list instanceof List<int>. So for the JVM, a List<Foo> and a List<Bar> are both the same class. Meaning that if you managed to cast a List<int> to a List<Object>, you would cast integers to object pointers.

  9. 1 month ago
    Anonymous

    Java doesn't have generics. It has regular types which store information using type-erased Object's; all of them are the exact same type, generic instantiation just wraps them in a facade that's purely syntax sugar

  10. 1 month ago
    Anonymous

    Historical mistake, project Panama is working on fixing that

    • 1 month ago
      Anonymous

      Sorry, Valhalla

  11. 1 month ago
    Anonymous

    >Remarks
    >Important

    >We don't recommend that you use the ArrayList class for new development. Instead, we recommend that you use the generic List<T> class. The ArrayList class is designed to hold heterogeneous collections of objects. However, it does not always offer the best performance. Instead, we recommend the following:

    C# always like this. Java is the well thought king

  12. 1 month ago
    Anonymous

    just wait for value types to get in

  13. 1 month ago
    Anonymous

    Coz everything in java must be an object, Java was designed around OOP, primitive types are used in very few cases.

  14. 1 month ago
    Anonymous

    Reverse shill thread created by .NET Foundation ®

  15. 1 month ago
    Anonymous

    It is very gross. Main reason why Go manages with such low memory usage and similar perf even with much worse compiler. Not everything is on heap. Slices are continuous in memory with no indirection to. Structs are as well if you don't ask for it to not to be.

  16. 1 month ago
    Anonymous

    >Why can't I make ArrayLists of primitive types in Java?
    I think that exists in the latest edition of java

    how fricking hard is it to use the fricking boxed type though?
    Are you one of those moronic bootcampers that can’t grasp the value of static type systems?

    • 1 month ago
      Anonymous

      Boxed types very wasteful. Gotta think of the poor ram stick

      • 1 month ago
        Anonymous

        Again thinking out if ass. Java'sown Integer wrapper does not waste resources https://stackoverflow.com/questions/26268507/do-custom-wrapper-classes-take-more-less-space-than-java-wrapper-classes

        • 4 weeks ago
          Anonymous

          Of course it does. That link doesn't say anything about not wasting resources, rather that it does waste. It's still an object with object header.
          Int slice in Go takes slice header + size of int * length space. Java int list takes list header + (class header + size of int) * length space. Java also includes a pointer load in every access where as go can use cache locality due to items being next to each other.

          • 4 weeks ago
            Anonymous

            Here is an illustration of how Java lists work vs Go slices. It's the same for classes/structs etc. Java makes constant garbage for gc, Go can manage memory in smaller boxes.
            It's why Go with it's lazier gc and worse compiler and still use less ram and perform well. It's all about data layouts and lack of heap allocations.

            Java is caching integers. Also, sometimes using littlebit more memory can dramatically speed up the computing.

          • 4 weeks ago
            Anonymous

            It caches some but still always has pointers and indirections. That should already tell you how crap it is. Java has to cache even integers.
            Using more memory can help but it depends on how you use that memory. Java way it's just a waste. Uses more memory and slows down accesses. Rather than just loading 1 have to load address and then load 1 from that address.

        • 4 weeks ago
          Anonymous

          Here is an illustration of how Java lists work vs Go slices. It's the same for classes/structs etc. Java makes constant garbage for gc, Go can manage memory in smaller boxes.
          It's why Go with it's lazier gc and worse compiler and still use less ram and perform well. It's all about data layouts and lack of heap allocations.

  17. 1 month ago
    Anonymous

    Just use Kotlin

  18. 4 weeks ago
    Anonymous

    Not only that, you will be able to make primitive and value classes that allow you to make your own custom primitives.

    • 4 weeks ago
      Anonymous

      >Brian Goetz
      How can a single man be so based?

    • 4 weeks ago
      Anonymous

      That is based after it arrives in another 4 years or so. It does lack the choice of use value type or use reference type. For example in lists you want array type. On single ones you often want reference type.
      Rather than choose when making class you should be able to choose when using it.

      • 4 weeks ago
        Anonymous

        Ah I read a bit more and that is how it works. Java decides whether to inline it or put it behind pointer indirection. Pretty much you'll always want to use value class if you can.

  19. 4 weeks ago
    Anonymous

    Scala exist precisely because java "designers" were brain-dead and bonehead.

    Everything has been done right in Scala 3

    .https://lngnmn2.github.io/articles/junk-food/

  20. 4 weeks ago
    Anonymous

    >They made their language so clusterfricked complicated that you need a tool tip to come up and tell you why doing the obvious thing is wrong.
    BWAHAHAH. I wonder when people will realize that 95% of the shit they type is just to make the compiler happy and they would unironically have less work if they wrote assembly, kek.

  21. 4 weeks ago
    Anonymous

    Java is an old language designed to be accessible on most devices at a time when memory allocation was a huge concern and blocker for most projects. Primitive types use less memory.

    • 4 weeks ago
      Anonymous

      That's exactly why it makes no sense why Java went the way they did. They chose to make everything a reference and everything into an allocation.
      Biggest reason why Java is so memory hungry is that one.

  22. 4 weeks ago
    Anonymous

    on the other hand you seem pretty serious starting a thread to vent your anger instead of performing a 5 second israelitegle search to resolve this matter.

  23. 4 weeks ago
    Anonymous

    >he just now learned about boxed types in java
    zoomer, please go.

  24. 4 weeks ago
    Anonymous

    because Java is an obsolete language for pajeets.
    come home white man.

Your email address will not be published. Required fields are marked *