OT: What's wrong with Java-the-language
Sean Kelly
sean at f4.ca
Sun Oct 21 08:35:31 PDT 2007
Julio César Carrascal Urquijo wrote:
> Yigal Chripun wrote:
>> What exactly is broken in Java that C# does better, in your opinion?
>> from what i see, anything that needs fixing is being fixed within the
>> Java community and I personally trust their decisions a lot more than
>> MS. Adding properties to a languages isn't considered "fixing" it, it's
>> just a convenience feature. On the other hand, removing covariance of
>> return types is a very big mistake. there are others of course, but
>> that one really pissed me off.
>
> Auto-boxing in C# works as expected. In Java you have to take care of
> implementation details that really don't concern to your code:
>
> C#
> Int32 a1 = 1, a2 = 1;
> Int32 b1 = 128, b2 = 128;
> Console.WriteLine(a1 == a2); // True
> Console.WriteLine(b1 == b2); // True
>
> Java-the-language:
> Integer a1 = 1, a2 = 1;
> Integer b1 = 128, b2 = 128;
> System.out.println(a1 == a2); // true
> System.out.println(b1 == b2); // false
>
> This is because they cache the first 127 integers as a singleton while
> you'll get different objects for 128 and up.
>
> Also, Generics don't guarantee that a collection will only contain
> elements of the same type:
>
> List<Integer> lint = new ArrayList();
> List lobj = lint;
> lobj.add("hello"); // WTF?
>
>
> And how come in Java you have to check your enums for null before using
> them? :D
>
> void foo(Color c) {
> if (null = c)
> // throw something.
> switch (c) {
> case Color.red: break;
> case Color.green: break;
> case Color.blue: break;
> default: break;
> }
> }
>
> Java-the-vm is a great implementation and I expect with anticipation a
> lot of useful languages to evolve on top of it, but Java-the-language
> isn't really a great example of language design.
Technically, the auto-boxing issue is related to the implementation
rather than the language design (unless that behavior is actually in the
spec). Generics, however, are utter garbage. They are useful as a
convenience tool for not manually casting and that's about it. Opinions
about MS aside, I think C# is a better designed language than Java.
Sean
More information about the Digitalmars-d
mailing list