• LongTimeLurker (unregistered)
    int frist = ((Integer)result.get(FRIST_INDEX)).intValue();
    
  • (nodebb)

    My suspicion, however, is that this code falls into the category of "C programmer forced to do Java". They're comfortable with an array of integers, which is covers 90% of the data types you use in C but a dynamic, complicated data structure is horrifying to them.

    Are you trying to insult me? (Also, this figure of 90% is, approximately, complete nonsense.)

  • (nodebb)

    dynamic, complicated data structure is horrifying to them.

    Yeah, no, I doubt that's how it works lol

    Most simple C programs are more complex than your average Java app, it's like saying a Java developer is scared by those complex single character commands in Logo.

  • (nodebb)

    The cast to Integer is not needed if the list is of type List<Integer>. Explicit boxing with new Integer() is also not needed since Java 5. My suspicion is that this is either very, very old code that predated the introduction of generics in Java 5, or the person who wrote it learned Java from a very, very old book.

  • Rob (unregistered)

    The cast to Integer makes me think that this developer was either using Java 1.4, or didn't know that generics existed.

    Also, the list-to-int-array can be simplified by using streams: result.stream().mapToInt(i -> i).toArray();

  • David-T (unregistered) in reply to Steve_The_Cynic

    The entire memory of the computer is an array of integers, what more could you possibly need?

  • (nodebb)

    TRWTF is Java not having primitive types and still using generic erasure. They should've pulled a .NET Framework 1.1 in the early days and put a breaking change in and fixed it then and there.

  • (nodebb)

    This is most likely old code - or code that was pasted and modified from an old tutorial/book. The casting of the result of get() to an Integer combined with the weirdness of manually boxing the int in the first place put this as pre 1.5 code.

    The moving of elements from an ArrayList to an array might just be premature optimization OR it might be that whatever they were doing further downstream with the results needed to take an array and not a List. If they were dealing with some third party API its actually likely that pre Java 1.5 you'd be needing to give it an array rather than a Collection of some type. (If they only processing in their own code that would be a wtf, though a mild once since pre 1.5 we were still at the stage where people would argue a lot about whether using the collections was actually worth the effort if you could do it with an array)

    I suspect this is just old code that would be a wtf if you wrote it today but was fine for the time it was written. (Now if we know that this was written post 2005? That's a different story)

  • (author) in reply to Jer

    This code is an older submission, but not nearly not 2005 old.

  • (nodebb)

    CloseUtils is also another brilliant antipattern given the try-with-resources... (I'm also a spring guy so this code makes me shiver in many other ways)

  • Drak (unregistered)

    Could it be (my Java knowledge is (luckily) very small) that 'result' is an ArrayList of Object, and that's why the cast back to Integer has to happen before the intValue can be retrieved?

  • LZ79LRU (unregistered) in reply to MaxiTB

    It is a hyperbole, to be sure. But there is some truth in it. As someone who started off before boxed types were invented I do recall the somewhat mild anxiety that came with giving up control over memory to a magic box made by Sun of all people. Suddenly this mission critical thing that you learned the hard way that you had to religiously babysit is completely out of your control and down to "trust me bro".

    Than again, early Java was crap in my humble opinion. So that played a part of it.

  • (nodebb)

    Code like this is also part of what gives Java a bad rep. Even if you start learning Java all by yourself today, you're going to find pre Java 5 guides and samples with crap like that. You can't expect a noob to know the difference between arrays, collections, and streams unless they already know what to look for. Pick up a random Java for Newbies book at your local library, the one with dust and spiders webs all over the cover, and you'll be horrified.

  • SG (unregistered)

    Agreed with others — that's perfectly normal Java code for pre-5... no autoboxing, and no generic lists so you have to cast everything, and as a result, a tendency to use those lists only to accumulate dynamically-sized results before copying them into a strongly-typed array. Not something which should be written today, but this certainly wouldn't have been a WTF twenty years ago.

  • Duke of New York (unregistered)

    As it turns out, TRWTF is two-tab indentation.

Leave a comment on “Integral to a Database Read”

Log In or post as a guest

Replying to comment #681028:

« Return to Article