7.0 wishlist?

H

Harold Yarmouth

I don't.

Not if you don't have the ability to change that class.
I see it as a maintenance nightmare. If methods are added to an
interface...

They shouldn't be, not once it's gotten "into the wild" anyway.
 
H

Harold Yarmouth

Mark said:
Interesting but not my cuppa. Break down and just type "implements" on
your class please.

The whole point is that sometimes you have a class that effectively does
implement some interface, except for lacking the actual "implements"
bit, and that you didn't write and don't get to edit. Generally you can
subclass it and slap "implements" on the subclass, but instances might
be getting created by code you don't get to edit that you'd like to
treat as implementing the interface ...
Feels yicky. Consider composition instead of inheritance.

Eh, the main use for this would be so you could tack on utility methods
to existing types, if they seemed to belong there more naturally than
somewhere else, and still use the resulting objects where the base type
is expected. Basically an auto-wrapper.
Probably too late for this, but sure it would have been handy.

Too late to change byte itself to unsigned, perhaps, but not to add an
additional type.
Does this require a runtime check on each assignment? Could be a lot of
overhead...

My thought was that the compiler would issue warnings if a might-be-null
reference (not either marked never null or found to be non-null by
static analysis, such as f in the else block of if (f == null) { this }
else { that }) was assigned to one marked never null, or errors, with a
cast needed to get rid of the warning or error that would produce NPE at
run-time. No run-time checks added anywhere else.

There'd only be anything different if the left hand side of assignment
(or a formal parameter being assigned) was of the "not supposed to be
null" variety AND what was being assigned was not either "not supposed
to be null" or demonstrably non-null by static analysis.

Error if demonstrably null instead.

If neither, one of three things might be done:
* Error, cast needed.
* Warning, cast can remove.
* Implicit cast.

Getting the NPE when the null first tries to get somewhere it doesn't
belong is valuable, though. I don't know how many hours I've spent
tracking how this null snuck into this ArrayList, that one into that
variable, etc., not to mention how some instance variable or another
managed to avoid being initialized.
I agree with Joshua, typo-city.
Eh?


Generic methods can do this now.

Methods, but not constructors.
Rolling your own for your own classes isn't hard.

But we have to use other peoples' classes, including especially Sun's
own, every day.
super();?

Called by a descendant, which can see protected constructors.
OK with me but apparently this ran into technical troubles.

How so?
At least they shouldn't be throwing unsubclassed RuntimeException. Are
they?

Yup -- com.sun.media.imageioimpl.plugins.pnm.PNMImageReader throws
unsubclassed RuntimeException instead of IOException or whatever when
the file format is unfamiliar.

java.lang.RuntimeException: What in the stream isn't a PNM image.
at
com.sun.media.imageioimpl.plugins.pnm.PNMImageReader.readHeader(PNMImageReader.java:187)
at
com.sun.media.imageioimpl.plugins.pnm.PNMImageReader.getWidth(PNMImageReader.java:153)

calling getWidth on a PNMImageReader invoked on a jpeg.

Really, though, unexpected/malformed/wrong/generally bogus input from a
source external to the program should produce checked exceptions.
Sure, makes debugging hard.

How? Warnings are just as visible as errors, whether using NB, Eclipse,
or command-line javac. You know it's there when you see it.
Dunno about this, just pick a different variable name.

Well, at least it should be consistent, so either that or hiding a field
should be an error too, at least if the field isn't inherited.
Hmm, I haven't looked at any existing frameworks for using
SoftReferences, but I'd head over to Apache.org and take a look.

I'm not presently in the market for a web server, but thanks anyway. :)
Personally I think the garbage collector is probably about as
complicated at Sun can handle at this time.

Who said anything about changing the GC? I was thinking more along the
lines of the allocator, and having a listener API for memory-running-low.
It's been discussed here, at least. I don't know how hard this would
be, but I'm in favor of it, Sun willing. The incremental garbage
collector gets pretty close to this, imo. It slowly prunes out un-used
objects as the program runs, thereby keeping actual memory footprint to
a minimum.

My observation is that a) -Xmx still exists and b) Java apps tend to
bloat to a fixed and large fraction of their -Xmx regardless of the
incremental garbage collector (now the default, isn't it?). My hope was
for -Xmx to go away (or be able to be set infinite, and perhaps default
that way) and the process size to tend to hang around a fixed multiple
(say, 4/3) of the actual amount of memory taken up by live objects
(since gc is more efficient if there's some slack space, similar to
hashtables being more efficient with some slack space).
I think they already have as nice a method as they can. Use finalize()
if you must. Personally I set all my windows to "DISPOSE_ON_CLOSE" so
they just to it for me.

I/O is the area where this tends to get the messiest. There really
should be a shortcut to the effect of

foo = whatever();
try {
do something
} finally {
foo.release();
}

Especially awkward is the situation where you want to actually return
the open resource after doing something with it. If you just use
try/finally your return will go through the finally and the stream will
close or whatever that you intended to return open. So you need to set
some boolean right before the successful-case return statement that the
finally clause looks at ...

One thing that might help there would be a deferred return syntax:

return = expression;
....
return;

with the former performing an assignment to a special sort of local
variable and the latter returning it. The idea being that if the return
type was a Releasable, the method might implicitly release anything
assigned to "return" but not actually returned, because of reassignment
(say of null) or an exception throw. Reassignment would release the
resource and an exception throw leaving the method would release the
resource referenced by "return" that isn't actually going to get returned.

Plus, say, the using or with block:

with (InputStream in = new FileInputStream(file)) {
actions
}

is three lines of boilerplate shorter than the try/finally above.

Three lines of boilerplate that get written thousands of times over a
Java programmer's career, mind. So it adds up.
Java arrays need a type, I think, which isn't aways inferable from the
context. Not sure how well this would work in practice.

Tightest bound on a common supertype of the arguments, obviously.
This would be handy, but what type are those arrays?


This is so easy to roll your own, I'm sure that's why no one has done it
for you.

Except that putting it in the base library code and giving the compiler
special knowledge of it would allow for pair literals, which makes the
arrays above able to work type-safely with the map's generic type
parameters; and it could be employed elsewhere to clean up parts of the
core API.
I think if Sun started messing with these, they'd go the other way.
Dimension is slow. Use the individual X and Y methods instead.

Dimension is raw field access. With JIT it should be as fast as anything
else.
* [int x]; defines a final box containing an int, an instance of a
SwingUtilities.invokeLater({foo:setVisible(true);});

Or you could substitute a "." for the ":" and save yourself a lot of
useless code.

The point was to get it into the anonymous inner class in a mutable
form, by shortcutting what you can already do, which is use a
one-element array instead of a straight reference. (What was that old
saw about adding one more layer of indirection?)
I'm with Joshua, the ternary operator is fine.

At least shorten it to allow x?foo:bar :p
No opinion. I've written your "yuck" code myself. It's really not that
common though, usually just doing file IO, which can be encapsulated
pretty well.

Begging your pardon, but that's like putting nuclear waste in lead-lined
casks and burying them instead of avoiding producing the nuclear waste
to begin with. :)
JSR is done, I think. I'm not really fond of more anonymous classes
though, I wish something more efficient could be used.

More efficient in what sense -- typing/source code bloat, not creating
lots of extra little full-blown classes, run-time memory use, or
run-time speed? Or some combination of these?
An un-overridable hashcode?

Yes, it should probably be final.
I guess, though I wonder if all platforms can always provide an
"identity" for each object.

It would just return Object.hashCode() -- that is, the return value
hashCode() either does have or else would have if it weren't overridden
anywhere in the ancestry.
What happens when an object gets shipped across a network several
times? Will it loose it's identity?

Object hashes are already not guaranteed to be the same in different
sessions or on different JVMs, save for some whose formulas are
specified somewhere (String's, perhaps).
I think the Apache folks may have a framework or three. Didn't actually
check though...

These deserve to be in java.util. Third-party stuff sees less use, since
users don't a) discover they exist as easily, b) have as easy a time
using them (they need to be found, then downloaded separately, and then
their Javadocs don't integrate well with Sun's, either not doing so at
all or going to Sun's website instead of your local copy and therefore
not working if you're offline, also eventually not pointing to the
current version anymore), or c) have as easy a time packaging up their
app after using them (and then the jar equivalent of DLL Hell may be
inflicted upon their users).

Plus, nobody goes looking for third party collection classes. They go
looking for third-party math libraries, web app frameworks, other
domain-specific libraries, and ImageIO plugins and the like.
Probably going to break a lot of stuff and make enums a lot less
efficient.

I specifically determined how to avoid doing so, which discussion you
didn't bother to quote one word of. :p
 
H

Harold Yarmouth

Andreas said:
It would fail of course. get returns a normal nullable Integer.
If there were a throwing variant of get(), and if the valuetype was
non-null Integer, then the returntype of that get() would be non-null
integer und thus could be assigned to such a variable. Easy, innit?

My preference is for the maybenull-to-nonnull assignment to be allowed,
but be an "implicit cast" of sorts that immediately throws NPE if the
maybenull actually is null. Think of it as having a ClassCastException
for nullability-typesafetiness.

Then nnIntRef = map.get("Blarg"); is perfectly legal, but throws NPE if
the map is missing that key (or has associated it with null). If the map
should definitely have that key, and it is a runtime error for it to
lack it, that expression being that short and succinct but throwing an
exception is exactly the desired situation. (If it's not a runtime error
for the map to lack the key, you use a normal reference instead of a
nonnull one.)

Perhaps also useful would be to let the exception be overridden:

Integer* nnIntRef (NoSuchElementException);
....
nnIntRef = map.get("Blarg");

then has the effect of

Integer intRef;
....
intRef = map.get("Blarg");
if (intRef == null) throw new NoSuchElementException();

If the exception is checked, of course, the assignment needs to be in a
try/catch or the method it's in declared to throw the exception.
 
H

Harold Yarmouth

Andreas said:
There isn't any real distinction between marker interfaces
like Cloneable and "normal" interfaces.

Lack of methods seems like a pretty big distinction between Cloneable
(and Serializable) and "normal" interfaces.
And any other type of compatibility inconsistent with the
instanceof-operator is right out of question, anyway.

Of course instanceof would continue to use the same semantics of
not-null-and-is-assignable-to that it currently has. It's just
assignable-to that might be a bit broader.
Yes, yes, yes! Not sure, if you got that idea yourself, or
from reading <[email protected]>.
(in case google distorts it: "slrngfmc50.4jb.avl" is the part
before the "at")

Eh -- I don't read using Google, and you don't appear to have posted
this using Google, so why would Google distort it?
As I brought it, it would subsume the functionality
of proposed typedefs plus add some more useful usecases.

With the added proviso that extensions of final classes can't see their
protected fields and methods. Essentially, "protected == private if the
class is final" would be maintained.
e.g. any negative value would have to be trivially smaller
than any unsigned value, and an unsigned value beyond the
range of the other signed value would have to be trivially
always larger. That is grossly unlike C's behaviour for
operators with mixed-signedness operands. And that isn't
yet all to it (what sign would be the result of mixed-
signedness addition?)

A can of worms best avoided. Make the ubyte type not work with other
integers at all without an explicit cast, or else do the usual Java
thing -- an implicit widening conversion to int and use int's arithmetic.
Sounds cool, principially, but I don't like to add a "line noise
character" for that feature, but rather some keyword.

Verbiage alert. This is a slight modifier that would be very common on
reference declarations, so it would be good to economize on typing or
visual clutter where it was used.
It wouldn't be possible to create arrays of non-null types,
unless there'd also be syntax to pre-initialize the elements.

String[] array = new String[50];
for (...) { ... populate array ... }
String*[] noNullsArray = array; // Runtime check that no element
// is null gets generated here.
String*[] another = {"Foo", "Bar", "Baz"};

Of course we could get into hairiness with noting whether the array
reference itself can be null:

String*[]* -- which * means which?

Maybe better to use

String[*], String*[*]. The * in brackets then clearly refers to the
array, and the * on String clearly refers to the element type, so the
former is an array reference that cannot be null whose elements can be null.

Arrays are something of a corner case anyway, since they should usually
Really little gain, given that most of the times one really should
do something with the value (especially in catch-blocks), and in
other cases, the name of some parameter gives a hint as to what
is expected there, (and may be used as such by overrides).

The cases I was thinking of are e.g.

catch (IOException) {
// Error recovery that is independent of the exact details of
// the exception
}

foo.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent) {
doIt(); // Independent of the event object, and nobody
// will ever subclass and override this!
}
}
Also, for unused method-arguments, the name is usually referred to
by the javadocs. You do javadoc your methods, don't you?

My anonymous inner class actionPerformed methods?

You're joking, right?

:)
May be useful in a few special cases, but sends a wrong message

No, it does not.
One shouldn't really use HashMap<...> typed variables in one's
code, but rather Map<...> typed ones for more flexibility lateron
(just assign a TreeMap instance to the Map variable instead of a
HashMap and don't bother with having to change all the variable's
types.)

I'm just asking for

Map<Key,Value> map = new HashMap();

The proposal would encourage use of:
HashMap<...> hashMap = new *(...);

The really-abbreviated new would of course be used for cases where the
types were the same.

StringBuilder sb = new(10);

foo.addActionListener(new() {
public void actionPerformed (ActionEvent) {
...
}
}

etc.

Obviously, the type in the constructor name is not redundant when it's
not the same type as the reference!
which would be a bad thing.

If someone is determined to write bad code, they will.
Indeed, for abstract classes' constructors: public is equivalent to
protected. So public could be mapped to protected for those. I see
no gain from that mapping, and even much less gain from demanding
programmers to change "public" to "protected". Since they are in
that case equivalent, it means it doesn't really narrow accessibility.
(which otherwise is a generally good thing to do, of course)

It just seems pointless.

On the flip side, the compiler's not permitting "abstract final" is
silly, since it would be useful for making one of those static-utilities
classes be both uninstantiable and unsubclassable. As things stand, you
have to put a private no-argument constructor in, which says the same
thing as "final" but in a much more verbose and less readable manner.
It is still good to *be able to* limit a process' memory footprint.
It just shouldn't be limited by default and then also too low (as it is now)
I guess, you meant it that way, too.

Yes. -Xmx would still work, but omitting it would result in the Java app
having the same memory limits as native code, whatever those might be
depending on hardware and OS.

But it would have to have some gc/allocator tuning to keep a not too low
and not too large amount of slack space. If heap size much bigger than
live objects, return some to OS; if not much bigger at all do an inc GC,
then grow if need be (and the bigger it gets, or if OS won't let it grow
any more, be more eager to do a full collection); etc.
That's the wrong approach.

Whoa! Why the sudden hostility?

No. Nothing that I have said is wrong.

I'm aware of these (and that they don't seem to work all that well --
they seem to actually behave more or less the same as WeakReferences).

But there are other things possible, too. For example, changes of
algorithm/strategy in parts of the program (e.g. use slower but less
storage-intensive methods to do some key piece of work if memory gets
tight). Lots of those kinds of responses (including "alert the user"!)
are not easily done by using SoftReference but are easily done by using
a listener.

Best to support both approaches, each useful for different things.
There is no sense for "SwingUtilities.invokeLater" to declare to throw
any checked exceptions. Unlike C's "fork", the SwingUtilities.invokeLater
doesn't "return twice": all the created threads don't know nuts about
SwingUtilities.invokeLater.

I think you've misunderstood me. The point was that this would be a
corner case, where the compiler would think that an exception could be
thrown somewhere where it actually wouldn't occur for exactly the
reasons you state.
This is an entirely different situation, and yes, that one does
make sense. Such a custom block structure would most likely not
take a Runnable, but rather a
"HaroldsRunnable<ThisException,ThatException,...>" :)

Having to declare all kinds of types like that explicitly would be a
pain, though. Having block literals that implicitly have such types
would be much nicer. (The types would still show up explicitly in method
argument declarations when programming to receive such things, though.
But that's hardly avoidable.)
I think there are a big lot of caveats that need to be dealt
with. It starts, where the Compiler needs to know, just what
is the Element-type. It can infer it in the "assignement-RHS"
case, but not safely elsewhere.

Why not just least common denominator? The most specialized type that
still is assignable from all of the types of the element expressions.
If the previous item has a solution, then this one can
easily be done by appending .toList() to the array-literal.

Wasteful in the extreme. Not just one intermediate object, but probably
actually N+1, and a whole extra O(N) copy of the collection.

Adding an Iterable-accepting constructor to the non-Map collections
seems ideal.
The Rectangle makes me feel uneasy about it. As a Pair of pairs,
it probably could no longer directly access its own data, but
would have to maintain two pointers to separate Dimension instances.
But then again, I may be wrong...

The JIT could work its usual magic on ones that were used and discarded
locally.
But much yuckier syntax ... I don't see the gain at all.

Not versus "real" closures, I'm sure. But it might pay off to think of
ways to sneak them in by the back door, so to speak. :)
How would this behave with Boolean x= new Boolean(false); ? :)
The object is not null, but means false (after auto-unboxing).

If the object is convertible to boolean, the boolean value is used. If
it's not, it's nullness is used. If it's a non-boolean primitive, it's
an error, or else its zeroness is used. (That last gives more or less
the same semantics found in C and C++, but without having a general
convertibility to boolean in any context, only the ternary operator.)
Another entirely different approach could be an
"exemptfromtry { ... }" block inside the try-block.

Oh, my God. Uggg-leee!
Quite a controversial topic.
Quite.

I could have sworn that I saw some static method of some
utility class that returned the original hashCode for any
instance.

Yes, but it really belongs as a final instance method of Object.
Even if it doesn't exist, I think
a static method in a reflection-related class would be a
better approach, than adding it to Object.

Why? Surely not some "adding things to Object is expensive" notion? This
wouldn't add a *field* or anything, after all, and one more method is
just one more entry in one more method table in one place.

In fact the default Object hashCode could then be reimplemented to just
call identityHashCode. There'd hardly even be more bytecode in the
Object class -- only the same amount that results from adding

int foo () {
return bar();
}

to a class.
Never so far found a need for that.

Well, I have. Lots of times.

The existence of IdentityHashMap is proof that someone at Sun also
thought that such a thing could be useful. They just didn't generalize it.
Is there any which using a wrapper for the Key object cannot solve?

Doing it without awkwardness. If the key has important semantics and is
acted on in other ways, having to extract it and wrap it all over the
place gets annoying very quickly and clutters up the code.

Besides, the exact same argument could be made for never introducing
Comparator (and thus for abolishing it now).
Comparator mostly exists because not all classes are
per se Comparable, but all classes are "Equalizable".

There are plenty of cases where also it is useful to have multiple
notions of order-comparison for one type, each such notion used in a
different context. And that right there often implies a different notion
of equality.
So far it looks like WeakHashMap<Key,WeakReference<Value>>
wrapped such as to transparently map the case of a nullified
WeakRef to a "not found" condition.

Maybe you don't want the key to be weak, though? Or don't want the map
to bloat up with dud entry objects. WeakHashMap presumably has some way
of making these go away. It's not easy to see how to implement such a
thing (even subclassing WeakReference and/or ReferenceQueue doesn't open
any new doors) oneself. References must use some VM-hook magic to do
their things, and making map entries that go away when a reference is
cleared likewise seems to require such.
Maybe they even do it with Soft- or WeakRefs.... Actually I wasn't
really sure, that interned Strings really had a chance of being collected.

I think they didn't used to be, in older Java versions.
Hooking into the GC has come up quite frequently here, and most likely
it's a bad idea in the first place.

ReferenceQueue already exists and somewhere there is code that enqueues
references on them. So the "hooking into the GC" at issue here is
already being done. ReferenceQueue doesn't expose any public or
protected methods that can be overridden to do the job, unfortunately,
but whoever can edit its private implementation can surely create such,
ergo Sun can, without changing one byte of the VM or GC implementation.

As it is, I think the effect can be achieved by making a Thread that
calls the blocking poll method on the queue and invokes listener
objects. So my proposal boils down to "put such a thing in the standard
API somewhere for everyone to use it without having to reinvent it". :)
I don't get that at all. What Subclasses are you now talking about?

Referring to the enum implementation, which has the enum constants
actually singleton instances of same-named subclasses.
Each instance of a given enum can be really one of an anonymous subclass
of the enum, but needs not. In
enum Foo { X, Y, Z}
There is only one class-file: Foo.class. no Foo$X.class, ...

Not on disk, no, but there are four classes in the system at runtime;
some ClassLoader magic sees to that.

There's likewise no MyResourceBundle.class on disk if you have a
PropertiesResourceBundle instead of a ListResourceBundle.
The case I could imagine was a SubEnum, that allowed a free
selection of a subset of BaseEnum's instances, and otherwise
behaves like a wrapper based on my own class-wrapper proposal
(messageid given in my comment to your second item).

Wrap, reduce range, or both. Yep.
* Now finally, I add one more idea to the list:

Distinguish between "using" and "implementing" an interface with
respect to accessibility.
The point being to allow to publish an (internal) interface
for return values (cookies), that foreign code may use as type
for variables, but not in "implements"-lists for classes.

One use would be for a library to return "handle" objects
from some of its methods, and accept these handles as parameters
to other methods, allowing user-code to do well-defined
tasks on these handles outside the library, but preventing
foreign code from implementing own classes for that interface
(and especially: possibly feeding those back to the library)
There are of course other ways to achieve that, like keeping
a WeakHashMap of valid handles, but that's far less elegant.

There's already a few other ways to do this:

public interface Foo {
void method();
}

public final class Bar () {
private static class RealFoo implements Foo {
public void method () { ... }
void otherMethod () { ... }
}
...
aMethod (Foo foo) {
RealFoo r = (RealFoo)foo;
r.otherMethod();
}
}

This one allows subclassing Foo, but throws ClassCastException if a
foreign Foo subclass is used. No WeakHashMap.


Another, even better, one:

public abstract class Foo {
Foo () {
// Package-private constructor.
if (!getClass().equals(RealFoo.class)) {
throw new IllegalStateException();
}
}
public abstract void method ();
}

This won't let anyone even instantiate a BogoFoo. Even using reflection
tricks, or exploiting the wart that you can't make something truly
package-private (invisible even to its own subclasses outside the package).


And then there's:

public final class Foo {
RealFoo delegate; // Package-private field. No subclassing.
public void method () {
delegate.method();
}
}

public final class Bar () {
private static final class RealFoo {
void method () { ... }
void otherMethod () { ... }
}
...
aMethod (Foo foo) {
foo.delegate.otherMethod();
}
}

which appears to cleanly achieve exactly what you want, save that
"delegate" could be molested using reflection (or, perhaps,
serialization hacks).
 
H

Harold Yarmouth

Mike said:
Then you'd have the source code for the original class, and could
comment out "final". :)

Maybe you want it to be "final" as far as everyone else is concerned,
though?
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andreas Leitgeb schreef:
Indeed, for abstract classes' constructors: public is equivalent to
protected. So public could be mapped to protected for those. I see
no gain from that mapping, and even much less gain from demanding
programmers to change "public" to "protected". Since they are in
that case equivalent, it means it doesn't really narrow accessibility.
(which otherwise is a generally good thing to do, of course)

I do see a good point here, since declaring it protected will prevent
people (that are not in a subclass) from trying to invoke it, which the
compiler allows, but then barfs at run time.
Never so far found a need for that. Is there any which
using a wrapper for the Key object cannot solve?
Comparator mostly exists because not all classes are
per se Comparable, but all classes are "Equalizable".

And also because from time to time, you want to use a non-default sort
order (like reverse, or just on another field as you usually sort on).

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAkkJilYACgkQBGFP0CTku6PyawCaAs7YJNLA3VAL7WMGJreWrJeW
ygcAn3Za2rcWtFMydVu59974gn0lHgTS
=43Jv
-----END PGP SIGNATURE-----
 
B

Bent C Dalager

Then you'd have the source code for the original class, and could
comment out "final". :)

Technically speaking, this is only guaranteed if the package in
question is sealed. I don't think this is the norm.

Cheers,
Bent D
 
H

Harold Yarmouth

Joshua said:
On this topic in specific:

The JVM has years of experience with tuning GC; the JVM's garbage
collector (all 3 of them?) is one of the best out there. One lesson of
the past few decades is that manual memory management is extremely
difficult to get right; a garbage collector which has been worked on for
over a decade is probably going to be managing its resources better than
any custom scheme you come up with for your application.

I wasn't considering messing with that. Rather, considering that an app
might have ways of dealing with low memory after the GC has done its best.
SoftReferences in particular are means of this

I wasn't considering messing with that, either. Rather, considering that
an app might have ways of dealing with low memory after the GC has done
its best. OTHER THAN flushing some "optional" objects.

Changing algorithm choices, for example, or otherwise gracefully
degrading to use less memory at the cost of speed or other tradeoffs.

Or simply warning the user they should save and close some documents.
In short: I'm sure the people who worked on the JVM GC are much more
knowledgeable in the topic than you or I. Trying to outwit them will
almost definitely result in failure.

On straight allocation matters, perhaps, but apps could take more
"long-range" actions besides freeing some objects Right Now, such as
switching to more memory-conservative but slower algorithms or data
structures for some internal purpose, or even advising the user to save
their work and reduce the number of open documents/whatever.

Another factor would be letting the user get away with trying to open a
too-large file or whatever instead of crashing and trashing all their
OTHER work. There should be some way to firewall OOME from affecting the
wrong things. Perhaps allocations on the event dispatch thread should be
favored, with a small portion of the heap reserved for such -- if
another thread (other than a system thread, mind you) wants to allocate,
but there isn't enough memory without using the forbidden set-aside bit
of heap, that thread gets OOME right there, sparing the EDT and critical
system threads. In practise, this means the SwingWorker charged with
loading the too-big document dies and the rest of the application lives,
instead of it being even money that the OOME b0rks up the EDT or
something else important and the UI goes bonkers, goes inconsistent, or
just plain goes away.
 
H

Harold Yarmouth

Mark said:
As you wouldn't be able to override hashCode and equals the contract of
these methods would be broken.

Only if you changed the equality semantics, which is doubtful since
you're not adding fields.
An annotation is being proposed to mark parameters etc as non null.

Ugly, verbose, and might not be checked by stock javac. Yuck.

@Override and the like are tolerable, because unlike @NotNull (or
whatever) they are placed before maybe 1 in every 300 lines of normal
Java code, not 1 in 10 or an even higher proportion.

Method argument lists could really suffer with an annotation-based approach.

Contrast:

String* method (int x, Object* y, String z, List*<String*> w) {

with

@NotNull
String method (int x, @NotNull Object y, String z,
@NotNull List<@NotNull String> w) {

What a difference! The former is much less cluttered and much more
readable. (And would an annotation even be able to be applied to a
generic type parameter?)
 
H

Harold Yarmouth

Andreas said:
No it wouldn't. Just because the following things would be
forbidden in such a wrapper class:

* overriding of any methods (overloading still ok)
* implementing any interfaces

Why not?
(That should cover all things that could change the
personality of an instance. I.e. things which could
make a baseclass instance be distinguishable from a
wrapper instance, (except for .getClass() and
"instanceof wrapper")

And reflection. (Which arguably getClass() and instanceof are part of.)
The expression (new Wrapper()).getClass() would return
the baseclass!

That might be a bad idea.
Good news. Lets see how that works out.

It sounds awful. Too verbose for how frequently it would ideally be used
in code. Often several times on one line (method declarations, plus any
use of generic types).
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Harold Yarmouth schreef:
No, it is not, and I will thank you to stop gratuitously insulting me.
You, sir, have an attitude problem.

If you have nothing pleasant or constructive to say, might I suggest
that you keep your mouth shut in the future?

Please keep in mind that telling people what to do on Usenet generally
doesn’t work. If you don’t like what people write, don’t read it, it is
the only way, I am afraid. There are long essays on this topic, which I
will not bother to google up for you :) Generally, responding to them
is a bad idea, therefore I snipped all other similar comments out below.
* Allow array literals in expressions other than assignment RHS.
Why the devil is foo(1, "string literal", 3) allowed but
foo(1, {array, literal}, 3) is not, even when foo's second
parameter type is Object?

new Object[] {array, literal} ?

Works, but if the array doesn't need to be modifiable, creates a
wasteful duplicate every time.

How so? Isn’t {array, literal} supposed to create one as well? The
method expects an array, after all. Oh, I see, it doesn’t. But even if
it expects an Object, there has to be an Object, so the array needs to
be created.
If you're worried that letting immutable arrays get used in such
contexts could somehow cause problems, keep in mind that this is already
possible:

int[] foo = {1, 2, 3};
...
fooMethod(1, foo, 3);

I don’t get it, foo is mutable.
You're joking, right? It makes an unnecessary temporary collection.

True, but ISTR that in Java, creating and abandoning a lot of small
classes if more efficient than clinging to one big class. So I wouldn’t
worry about this small class that gets created here. That’s the GC’s
responsibility.
In
fact, all the collections really ought to have constructors that take an
Iterable and just iterate over it.

That seems like a good suggestion, indeed.
In many cases, they can be
implemented in all of two lines of code:

super();
addAll(iterable);

given that addAll gets broadened to allow any iterable.

Which would be consequential (in the sense of being consequential) on
allowing the constructor to take one.
Or at least

super()
addAll(collection);


Now you're making a whole extra class. How efficient.

How would this be less efficient? You’re creating a HashMap anyway.
Oh, you mean the extra class object. I doubt it will make a difference.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAkkJjvQACgkQBGFP0CTku6M87gCgmHxKuMjdXxTr62YXIQdp8A/4
vDIAoJCGS9RBfmA7BGGDkEIvdS8MdFH+
=sQhw
-----END PGP SIGNATURE-----
 
R

Roedy Green

That works fine now.

It might be this is just something IntelliJ lint is picky about, or it
could be the catch as you describe. I have got in the habit of making
throws, throw, catch... match perfectly so I can't remember the
precise problem I used to have.

The problem with what I do now, is that I do a lot of maintenance of
throw, throws, catch at various levels in the hierarchy, which is very
rude in code used by other people. I should give them a stable throws
interface which leaves room for future changes.

I ran into this often writing stub or debug code, then later replacing
it with production code that actually threw the exceptions.
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Harold Yarmouth schreef:
I'm not presently in the market for a web server, but thanks anyway. :)

I think you don’t understand. He refered to
http://commons.apache.org/collections/, specifically to
http://commons.apache.org/collectio...che/commons/collections/map/ReferenceMap.html.
But note that *the* big disadvantage with Jakarta Commons is no
generics, although finally, there is an effort going on.
These deserve to be in java.util.

I tend to agree here, but they have to be cleaned up first. And
generics, of course.
Plus, nobody goes looking for third party collection classes. They go
looking for third-party math libraries, web app frameworks, other
domain-specific libraries, and ImageIO plugins and the like.

Well, they should be. Collection classes are amongst the most difficult
to implement well, IMHO.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAkkJkdQACgkQBGFP0CTku6MDYQCfczXfaee8kE8wyd7zcMKX+A9O
vmMAn3cE3kWv2hxZOCzPZfYzpcscQcvO
=O6ZH
-----END PGP SIGNATURE-----
 
B

Bent C Dalager

Harold Yarmouth schreef:
If you're worried that letting immutable arrays get used in such
contexts could somehow cause problems, keep in mind that this is already
possible:

int[] foo = {1, 2, 3};
...
fooMethod(1, foo, 3);

I don?t get it, foo is mutable.

In theory, though, a compiler might decide to retain the actual array
object between invocations since its size will always be the same,
it's only the contents that is mutable.

It would have to do a lot of analysis beforehand though, to make sure
no one else has retained a reference from a previous invocation. Seems
a bit dicey overall :)

Cheers,
Bent D
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Harold Yarmouth schreef:
My anonymous inner class actionPerformed methods?

You're joking, right?

I wouldn’t have been. Ok, Javadoc is unnecessary, but for maintenance
purposes some comment makes sence. Might as well be Javadoc
(Alt-Shift-J generates it in Eclipse, and I can never remember the
shortcut to create a block comment, since I almost never use them).
On the flip side, the compiler's not permitting "abstract final" is
silly, since it would be useful for making one of those static-utilities
classes be both uninstantiable and unsubclassable. As things stand, you
have to put a private no-argument constructor in, which says the same
thing as "final" but in a much more verbose and less readable manner.

You are stretching the intended semantics of ‘abstract’ here. It is
meant to mean: this class should be subclassed to fill in functionality.
It is not intended to mean ‘this class has a constructor which you may
not use’.
Wasteful in the extreme. Not just one intermediate object, but probably
actually N+1, and a whole extra O(N) copy of the collection.

Mind elaborating how you get these numbers? I don’t find that obvious.
Oh, my God. Uggg-leee!

But feels more in line with the current syntax to me. I’ve often felt
the need for this.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAkkJm5MACgkQBGFP0CTku6PK4QCfcCulhrfjFpN+dwX4KlCM+t1f
VCYAoLKnHx2oFZ925/Q7SQIG9vbh1PGB
=J8Vt
-----END PGP SIGNATURE-----
 
J

Joshua Cranmer

Harold said:

How many interfaces are there in core Java code alone? With these
change, my class would effectively implement dozens of interfaces that I
didn't know exist and whose contracts I am probably violating.
* When a type has a one-argument plus() method, + can be used when the
left hand operand is of that type and the right hand operand is of an
argument type for which the former has a one-argument plus() method.

[ ... ]

A poor way

No, it is not, and I will thank you to stop gratuitously insulting me.
You, sir, have an attitude problem.

Then how do you propose to add such features as LHS-based operations,
like 2 * matrix?
If you have nothing pleasant or constructive to say, might I suggest
that you keep your mouth shut in the future?

I'm sorry. I assumed you had been a denizen of this newsgroup for a
while and therefore had seen my copious commentary of operator
overloading in the past year or two (which has come up in at least three
separate threads).
Other languages are irrelevant.

They are relevant. What you are proposing would be counterintuitive on
multiple levels:

1. Visually === is "more" (i.e., more stringent) equal than ==. That
implies that === would have to become identity equality while == would
become equals()-based equality.
2. This is a COMPLETE reversal of practically every single dynamic
language on here.

Once again, this has been discussed in more detail quite recently
(within the last month, IIRC), so I'll defer to you look at those
threads in question.
Sure I have. Did you even bother to read my entire post before clicking
"Take A Crap All Over It And Send" in your news reader?

I reply to large posts as I read them.
new Object[] {array, literal} ?

Works, but if the array doesn't need to be modifiable, creates a
wasteful duplicate every time.

It's doing the exact something the JVM would be doing anyways. In terms
of bytecode, there's no advantage except dropping some extra typing.
Note that Java looks unlikely to drop extra typing merely for the sake
of extra typing based on historical fact.
You're joking, right? It makes an unnecessary temporary collection. In
fact, all the collections really ought to have constructors that take an
Iterable and just iterate over it. In many cases, they can be
implemented in all of two lines of code:

This is the first suggestion I've seen that would have a very strong
chance of making it in (although not the first worthwhile one, others
were also worthwhile).
Now you're making a whole extra class. How efficient.

Doesn't require any changes to existing libraries, the JLS, and the JVM.
It's slightly more verbose and no easier to scan for.

It's not something I'll belabor, but most people would probably prefer
the second form merely because it obviates that x is an Object and not a
boolean.
Now you've gone from "nonconstructive" to "just plain bloody-minded".

I have many problems with closures, and so do many others in this
newsgroup. My (and others') complaints are well-documented on this
newsgroup. I cannot feel any sympathy for you if you did not look to
gauge our reactions to basic
In your humble opinion.

Knowing how enums are implemented, you'd basically have to change nearly
every aspect of implementation. I don't see how you could make this
possible:

public enum SomeEnum {
A { void foo() { "Foo!"; } },
B { void foo() { "Bar!"; } },
C { void foo() { "Ugh!"; } };
abstract void foo();
}

public enum Enum2 extends SomeEnum {
A, B;
}

since SomeEnum$A, SomeEnum$B, and SomeEnum$C inherit SomeEnum.
 
L

Lew

Joshua said:
I'm sorry. I assumed you had been a denizen of this newsgroup for a
while and therefore had seen my copious commentary of operator
overloading in the past year or two (which has come up in at least three
separate threads).

None of the nasty things Harold says or implies about you are true, Joshua.
 
L

Lew

Hendrik said:
But note that *the* big disadvantage with Jakarta Commons is no
generics, although finally, there is an effort going on.

I lost a lot of respect for the Apache Commons projects when the commons-lang
project refused to fix the bug in their 'enums' implementation that relies on
a reference to the 'class' literal initializing the class itself.

This used to work prior to Java 5 due to a bug in the implementation of Java.
When Sun fixed the bug, commons-lang broke under that circumstance. The PTB
of the commons-lang project refuse to fix their bug.

WTF?
 
L

Lew

Sorry about the accidental post - I fumble-fingered it.


Harold said:
Eh -- I don't read using Google, and you don't appear to have posted
this using Google, so why would Google distort it?

This might or might not have occurred to you, "Harold", but others beside you
read this newsgroup. Some of them use GG. Andreas was being responsible for
that, and advising other readers how to decipher his post. He was not talking
only to you.
 
L

Lew

Andreas Leitgeb schreef:
Hendrik said:
I do see a good point here, since declaring it protected will prevent
people (that are not in a subclass) from trying to invoke it, which the
compiler allows, but then barfs at run time.

Not true. I just tried it, and the compiler complains.
$ javac testit/AbstractModel.java testit/Foo.java
testit/Foo.java:51: testit.AbstractModel is abstract; cannot be instantiated
AbstractModel am = new AbstractModel();
^
1 error

AbstractModel has an explicit public constructor.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top