Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Stevens Miller
Bartender
Posts: 1223
23
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic