- Feature Articles
- CodeSOD
- Error'd
- 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
Sorry, I'm a long-time reader and have enjoyed this site for years, but there is zero chance I'm going to read that much code. It can't be amusing enough to be worth it.
Admin
I've always wondered why Java has the Iterator class and various List and Map objects if all everybody seems to do is implement everything as an array with indices.
Similarly, what on earth is the point of the List interface? Nobody ever uses it. They just trundle on brainlessly casting direct to ArrayList.
Admin
It smells like they thought they knew what the structure of the classes should be, but were mistaken. There are more things in the Java type system than in .NET where you look at it and go "WTF?"
Admin
When you cast List to ArrayList, you should ask yourself what's so special and specific about ArrayList that you can't use it as a generic list.
In my experience, there isn't anything special about it 100% of the time, so I don't cast.
Admin
Based on the diff, both classes share the same serialVersionUID which is not supposed to be the case. If those classes actually use Java's built-in serialization, that'd break badly at runtime, which tells me that they're not using Java serialization (pretty common) and they just added those serialVersionUIDs to silence the lint warnings about their lack.
Admin
Well, since ArrayList extends the AbstractList class, which implements the List interface ... the main thing you have to ask yourself in Java is whether or not you are dealing with an ArrayList. Otherwise you are downcasting to a null, as far as I can see.
And given this Java inheritance hierarchy (assuming I have it right), your ArrayList already does everything that a List does, you'd be mad to write code that accepts a List but requires the extra functionality of an ArrayList. Because unless the collection is indeed an ArrayList, that functionality is not there.
The problem, I assume, comes when you as the call site want to invoke a method that depends upon an ArrayList, but what you actually have is a List (or possibly an AbstractList). I'm wide open to correction here, because I have studiously avoided Java for twenty five years and six or seven major versions of the language, but as far as I can see you'd need to try a Java.lang.Class.cast() from a List to an ArrayList. Which, unfortunately, might result in a ClassCastException.
From a C# perspective, it all looks a bit messy. (Though I could very well be wrong.) Of course, in the general case, you'd just refactor methods to accept a List rather than an ArrayList, but that might not go down too well when you're dealing with a million line code base.
Admin
If you have been here for years, then you should already know that this certainly isn't the longest block of code posted in its entirety.
Admin
The listColumnNames method should have been static. It doesn't depend on any single instance. However, instead of using TableColumns.listColumnNames(), anyone using it is now forced to use an instance: TableColumns.Label.listColumnNames() or TableColumns.Color.listColumnNames().
Admin
Seems like a big case of the "just-in-case's". Just in case YLineGraphTableModel needs to diverge from XLineGraphTableModel, it's been made into its own class. What a waste! Kind of goes to show how little planning was done at the very beginning.
Admin
Well this is a pretty literal example of an XY-problem
Admin
To a C# developer like me, this code looks like spaghetti code to me. Casing is all over the place, and everything looks so alien. Like there's no property and enums are just syntactical sugar instead of real, well, enums. So strange. I couldn't really tell if it's good Java code, cause to me it just looks like bad C++ code.
Admin
It appears that there’s a field named “lgm” in the abstract class, which is accessed by both the X and Y implementations.
Significantly, the X implementation gets the “X” data from this field, whereas I assume the Y implementation uses the “Y” data from that class - the line showing “lgm.getXDataSeriesSettings” in the diff isn’t just a renamed variable, it’s a significant difference.
Ideally, the developer would have created an abstract “getSeriesSettings” method in the parent class, rather than re-implementing getValueAt and setValueAt in their entirety. Overall though, this isn’t nearly the WTF the article seems to suggest.
Admin
This is not correct. The
serialVersionUID
is a version number for the class. If you serialise an instance of the class and then make incompatible changes to it, you bump theserialVersionUID
so that the deserialiser knows that it can't deserialise the old data. It's absolutely fine for two different classes to have the sameserialVersionUID
. Essentially, it's just a version number for that class.This is almost certainly true. It's true of pretty much all the Java code I ever wrote using Eclipse, until I understood what it was really for.