27.04.2013 Views

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

General <strong>Java</strong> Questions III<br />

specific to traversing a Hashtable).<br />

If this doesn't help, maybe you could clear up what you mean by Enumeration having<br />

defined methods.<br />

--<br />

Eric<br />

Q: can anyone provide an example on how to use clone() and clonable<br />

interface?<br />

Answer:<br />

//Class Point uses default clone implementation that returns<br />

//shallow copy of Point (which is sufficient in this case).<br />

class Point implements Cloneable {<br />

int x, y;<br />

}<br />

class ImmutableRectangle {<br />

private Point lowerLeft = new Point();<br />

private Point upperRight = new Point();<br />

public Point getLowerLeftPoint() {<br />

try {<br />

return lowerLeft.clone();<br />

}<br />

catch(CloneNotSupportedException e) {<br />

//shouldn't occur since Point is cloneable<br />

throw new InternalError();<br />

}<br />

}<br />

}<br />

we don't want Rectangle points to be changed outside its class. the best<br />

way would be to create a copy of Point object and pass it.<br />

i5mast<br />

MVP for <strong>Java</strong> 2<br />

http://www.brainbench.com<br />

Pick your topics, and we'll send you great deals, free<br />

information, and special offers by email from Focalex.<br />

IT Professional General Computer Design and Graphics Linux Freeware/Shareware<br />

Games Intranet Computer Hardware Web Design Computer Software<br />

UNIX Web Software Windows Software Personal Finance Programming Software<br />

<strong>Server</strong>s C/C++ Powerbuilder Perl XML<br />

<strong>Java</strong> SQL Design/Graphics Utilities Handhelds<br />

Get FREE STUFF, special offers and information on the <strong>Java</strong>, C/C++,<br />

SQL, XML and another languages programming topics YOU want to hear<br />

about delivered to your inbox!<br />

Unix, Windows Software/HardWare, Handhelds - just pick YOUR<br />

interests and start getting the stuff you want today. The best<br />

free info and deals on computers, software and much more by email.<br />

SUBSCRIBE for FREE HERE<br />

file:///F|/350_t/350_tips/general_java-III.htm (8 of 9) [2002-02-27 21:18:30]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!