- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- There's No Place Like
- Lucky Penny
- Mike's Job Search Job
- Teamwork
- Cuts Like a Knife
- Charge Me
- Que Sera, Sera
- Hot Dog
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
Are you trying to insult me? (Also, this figure of 90% is, approximately, complete nonsense.)
Admin
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.
Admin
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.
Admin
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();
Admin
The entire memory of the computer is an array of integers, what more could you possibly need?
Admin
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.
Admin
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)
Admin
This code is an older submission, but not nearly not 2005 old.
Admin
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)
Admin
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?
Admin
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.
Admin
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.
Admin
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.
Admin
As it turns out, TRWTF is two-tab indentation.