- Introduce string primitive It would be just as the String class, except it would never be null, it would be empty string instead. How much boiler plate code does the null-checks cause for String. Autoboxing would work too.
- Make generics array-like By introducing generics Java creators worked hard to ensure backward compatibility. And, IMHO, failed. Consider:
- Array of Integer objects can be casted to array of Number objects, but not so collections.
- If you insert something illegal to such downcasted array, you get appropriate exception.
- Collections were not designed to throw exception due to incompatible type, as they were designed to always hold Object references. Changing that could break existing code.
- Any down/up-casting was not permitted on generic collections for the same reason.
- If you're not sure, what your legacy code inserts into raw collection, pass in the one, that hold Object and you'll get no issues.
- If the legacy code is supposed to only insert certain type (say String), so pass in appropriate collection. In case the legacy code inserts something else, you get exception at exact place where the bug in legacy code lays, rather than get an ugly ClassCastException miles away in the new code.
- Allow public fields by JavaBeans specification Probably 90% of classes conforming with JavaBeans specification have only trivial setters and getters. I see no real reason, why public fields are not allowed and all this boiler plate code must be written.
- Enhanced for should be null-safe Why it's not called for-each, like in other languages?
- Allow pass-by-reference or multi-value returns It really is nasty to write a new class just to return several values from method. I'd love to have something like C++ references or Pythons multi-value return for that.
- Replace java.io entirely Just admit - java.io is hopelessly overengineered. The most clumsy and least usable I/O system of all languages I've ever used. With this number of classes you'd expect to have stuff for all possible cases, but in reality there never is a class, that does what you need. You have to combine at least two of them in all cases. And if you need to read a simple text file, out of all there trouble all you get is readLine() - parse it yourself. How to fix it? Just make a clone of C++ iostream - with a couple of rough edges removed and couple extra classes (like for pipes and sockets) it would be nearly perfect solution.
- Package aliases or smallest unique distinction One thinkg I don't like about Java packages is the all-or-nothing approach with their names. In case you have 2 classes with same name, you have to use both of them with full package qualification. With standard reverse-domain naming scheme this means ugly long names. What I'd like is aliases, similar to C++ namespace aliases, which could look like:
As for consistency, other primitimes could also allow called methods of their relevant class alternatives.
This type of for statement was introduced for readability, but having to check for null takes away half of that, because you have to wrap it in an if (you can avoid if by writing apropriate condition in traditional for).
IMO this enhanced for should treat null collection as empty.
package alias = com.company.product.whatever.pkg;
With this line alias.ClassName is identical to com.company.product.whatever.pkg.ClassName.
Another solution could be to use the unique part of package name: move backwards from class name to any dot until you get uniques name. Perhaps whatever.pkg.ClassName is enough to identify class and you don't need to type the full ugly package name.
Komentarų nėra:
Rašyti komentarą