aspose file tools*
The moose likes Features new in Java 7 and the fly likes What feature that you wished Java 7 had that isn't in? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "What feature that you wished Java 7 had that isn Watch "What feature that you wished Java 7 had that isn New topic
Author

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

Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

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

Joined: Aug 22, 2010
Posts: 3610
    
  60

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

Joined: Aug 25, 2005
Posts: 231
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.


Thanks and Regards
Omkar Patkar (SCJP 1.4)[url]http://javacollectionsnotes.blogspot.com[/url] | [url]http://omkar-myscjpexp.blogspot.com[/url]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4655
    
    5

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
Bartender

Joined: Jan 17, 2008
Posts: 2368
    
  28

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: What feature that you wished Java 7 had that isn't in?