• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic