The Artima Developer Community
Sponsored Link

Weblogs Forum
JavaOne 2010: Upcoming Java Features

47 replies on 4 pages. Most recent reply: Oct 30, 2010 11:19 AM by Morgan Conrad

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 47 replies on 4 pages [ « | 1 2 3 4 ]
Ian Robertson

Posts: 68
Nickname: ianr
Registered: Apr, 2007

Re: JavaOne 2010: Upcoming Java Features Posted: Oct 7, 2010 10:11 AM
Reply to this message Reply
Advertisement
> > Nobody seems to have commented much on four of the new
> features. ...
>
> Strings in switch statements are nice. Do we get the
> ability to use additional classes in switch statements? I
> think I know the answer, but I can't figure out the rationale.

For now, it seems that the answer is indeed no. The rational is somewhat reasonable: String is an immutable class with a well-defined hashCode that the compiler can compute to generate efficient code. To support this for arbitrary user classes would require the compiler to load those classes to compute the hashCode constants for each matched instance. Having the compiler load and execute arbitrary user code would probably be a non-starter.

Mark Thornton

Posts: 275
Nickname: mthornton
Registered: Oct, 2005

Re: Autoclose interface Posted: Oct 7, 2010 11:16 AM
Reply to this message Reply
> > If you implement the autoclose
> > interface, you can put input and output streams in a
> single try block
> > and, when the block ends, all of the streams are
> closed.
>
> What does that mean exactly? Destructors and RAII in Java,
> finally? Too good to be true.

The mechanics are different, but that is the practical effect.

Morgan Conrad

Posts: 307
Nickname: miata71
Registered: Mar, 2006

Another Idea for a Java Feature Posted: Oct 30, 2010 11:19 AM
Reply to this message Reply
More of a Swing feature actually.

As computers become more multi-core, we're encountering more and more thread-related issues with Swing, which, ultimately, are caused by what are, or should be treated as, ConcurrentModificationExceptions. Because data is getting modified on non-AWT threads. Which, of course, is technically a programming mistake, but one that's fairly easy to make.

So, how about changing the paint() method to catch and handle these exceptions. e.g. (with some possible filler code added)

public void paint(Graphics g) {
  try {
    // existing paint code goes here, or. if we are a subclass:
    super.paint(g);
  }
  catch (ConcurrentModificationException cme) {
    if (Boolean.TRUE.equals(getClientProperty("HandleConcurrentModificationException"))) {
      doHandleConcurrentModificationException(cme);
    }
    else
      throw cme;
    }
  }
}


doHandleConcurrentModificationException() is a protected method that, by default, just calls repaint();

Thoughts?

Flat View: This topic has 47 replies on 4 pages [ « | 1  2  3  4 ]
Topic: Practical Scala/Java interoperability by small examples Previous Topic   Next Topic Topic: Why To Go Into Bioinformatics

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use