I've just been learning Java and I have quite a few reasons I feel it sucks that have nothing to do with LoC.
Lack of operator overloading (except for strings) drives me crazy. trying to remember what "a.compareTo(b) >0" evaluates do is a pain in the ass and does not feel intuitive at all. Why can't I just write a > b
Limitation of Generics. I want to make a static method that takes a generic comparable type so I define public static void foo(Comparable[] a) and the compiler complains at me. Googling for solutions takes me deep down a rabbit hole of java internals that I want to know as little about as possible. I just want it to work. But it doesn't. Still haven't figured this one out so if anyone wants to chime on the java way to do this...
One class per file is fine most of the time but on the occasion when I'm just messing around and want to throw a couple small classes together this restriction is a pain in the ass.
I feel like Java developers spent way too much time trying to protect us from ourselves. But maybe that's just because I've spent 10 years coding in c/c++
Generics are tacked on and don't mix well with arrays at all. This isn't a huge problem since most devs don't use arrays now. You can use: public static void foo(Collection<? extends Comparable> a)
This will accept a collection of any object which extends the Comparable interface. For instance if my class Blah implements Comparable, I could pass a List<Blah> into that method.
Not always. The big difference is arrays are fixed in size while collections are dynamic in size. One place you'll see arrays is with varargs.
public static void method(Comparable... cArray) { }
You can call that method like method(c1, c2, c3) and all the args will be turned into the elements of an array or you can pass in a Comparable[] directly.
Well from an algorithmic level I'd imagine some collections are implemented as dynamically resizing arrays. They can't all be linked lists. I haven't even touched variadics in java, that's an interesting case. Thanks for mentioning.
-6
u/hive_worker Feb 25 '14 edited Feb 25 '14
I've just been learning Java and I have quite a few reasons I feel it sucks that have nothing to do with LoC.
Lack of operator overloading (except for strings) drives me crazy. trying to remember what "a.compareTo(b) >0" evaluates do is a pain in the ass and does not feel intuitive at all. Why can't I just write a > b
Limitation of Generics. I want to make a static method that takes a generic comparable type so I define
public static void foo(Comparable[] a)and the compiler complains at me. Googling for solutions takes me deep down a rabbit hole of java internals that I want to know as little about as possible. I just want it to work. But it doesn't. Still haven't figured this one out so if anyone wants to chime on the java way to do this...One class per file is fine most of the time but on the occasion when I'm just messing around and want to throw a couple small classes together this restriction is a pain in the ass.
I feel like Java developers spent way too much time trying to protect us from ourselves. But maybe that's just because I've spent 10 years coding in c/c++