Re: a Problem with java 2D
Chris ( Val ) wrote:
On Nov 4, 1:32 am, Lew <l...@lewscanon.com> wrote:
Chris ( Val ) wrote:
The reason I ask is because your SSCCE does not compile for me.
Oop's [sic], I meant there are 2 warnings, sorry :-)
and they are ...?
My apologies for not posting them.
Compiled using version: "1.6.0_02"
Here are the two warning I received:
C:\Java\classes\NewJFrame.java:19: warning: [serial] serializable
class <anonymous NewJFrame$1> has no definition of serialVersionUID
pane = new JPanel(){
^
C:\Java\classes\NewJFrame.java:5: warning: [serial] serializable class
NewJFrame has no definition of serialVersionUID
public class NewJFrame extends JFrame {
^
2 warnings
It's a warning instead of an error because Serializable classes don't need an
explicit serialVersionUID; in its absence Java generates one for you. It's a
warning at all because leaving it at the default can cause you maintenance pain.
Have you read the Javadocs for java.io.Serializable? They discuss this member
variable there. Also, Joshua Bloch's seminal /Effective Java/ covers
Serialization in detail.
To implement Serializable is a solemn responsibility that a lot of people hack
through, then wonder why they have trouble later. It exposes details of
implementation, violating OO encapsulation, and locks in aspects of the class
design. Failing to account for that causes trouble. It can be horridly
inefficient, unless you take care. You can have trouble with modifications to
a class if it is enhanced (refactoring, additional features, ...). It's
actually a fair amount of work to make something Serializable correctly.
Also note the placement of the parenthesis, in the following piece of
code:
EventQueue.invokeLater(new Runnable()
{
public void run()
{
new NewJFrame().setVisible(true);
}
});
Do you see a problem here?
No. What is your point?
--
Lew