Forums Register Login

What feature that you wished Java 7 had that isn't in?

+Pie Number of slices to send: Send
 

Paul Clapham wrote:...the listener might be called superfluously.


I should add that I'd be concerned that "superfluously" here might, instead, have been "catastrophically."

For instance, if a listener is created in reliance on the availability of a resource that later becomes unavailable, a naive programmer might think they can avoid untimely attempts to use the resource by "destroying" the listener. Something like this:

The mistake, of course, would be to assume that Line 5 destroyed the listener; it doesn't, as the eventGenerator still holds a reference to it (even if it's a weak reference, if the GC hasn't gotten around to it). But, this works in hoary old VB6, because Line 5 does destroy the listener object and the language itself doesn't send events to destroyed objects.

I would certainly grant that the above would be awful practice in Java and is not much of a case against explicit removal of listeners (since "list=null" might as well be "eventGenerator.removeListener(list)"), but what if the above fragment were in a method such that list were created locally? Again, a naive Java programmer might assume that an instance with a reference to it held in "list" was destroyed when list went out of scope. Again, that's not what happens. But, it means a programmer might not even have anything like Line 5, and could still close a resource passed to the listener (maybe outside the method that had created the listener).

All in all, it seems like something the language could have, with no backwards compatibility problems, and lots of useful future applications.
+Pie Number of slices to send: Send
Some time ago I came across Google Guava's EventBus. Though it doesn't provide automatic deactivation of listeners the way VB6 did, it might still be easier to unregister a listener there - you'd do it once, regardless of how many producers it is intended to listen to. Or you can throw the entire EventBus away - this might be very useful when implementing a complex form with lots of listeners; when the form closes, just throw its EventBus away.

Unfortunately, by the time I've discovered the EventBus, I had such a complex form already implemented the old way.
+Pie Number of slices to send: Send
I wish there was some common thing between JDBC classes and the classes in collection framework....
for e.g. .... most general requirement is a ResultSet needs to be converted to some collection, list or map....
so i wish there were APIs in java such that....resultset can be converted to desired collection.
1
+Pie Number of slices to send: Send
Collection of what? The only thing I can think of is a List<Map<String, Object>> where each List element is a mapping from column names to their values.

You could check out Apache Commons DbUtils though, with its QueryRunner and BeanListHandler.
1
+Pie Number of slices to send: Send
 

omkar patkar wrote:resultset can be converted to desired collection.



Sorry, I think this is a really bad idea. If you want it done for you, Hibernate and similar tools do a good job.

What do you think your wished for tool would do when you return millions of records, each with lots of stuff? Load it all into memory?
1
+Pie Number of slices to send: Send
 

omkar patkar wrote:I wish there was some common thing between JDBC classes and the classes in collection framework....
for e.g. .... most general requirement is a ResultSet needs to be converted to some collection, list or map....
so i wish there were APIs in java such that....resultset can be converted to desired collection.



You mean like you can provide a configuration file that provided the mapping between class and table, and also the mapping between database column and bean property, and then when you query the database, it will return a list of objects?

Because there's already something like that. It's called JPA
He's my best friend. Not yours. Mine. You can have this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2757 times.
Similar Threads
* Welcome Jeff Friesen
What are your top 5 features that you love about Java 7?
What are the top 3 Java SE 7 features you can put use straight way
Queries on Java 7 Beginner book.
can anyone tell me how to get "Java 2.0 by Example" by JEFF FREISEN
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:25:00.