On 1/5/2012 4:42 PM, Friedrich Clausen wrote:
Hello,

In section 1.2, in exercise program Set-HashSet-FindDup we declare a
new HashSet like so -

Set s = new HashSet();

but I notice that

HashSet s = new HashSet();

also works. What is the recommended way to create a new HashSet
instance?

This is indeed a very important question - "When do you want to use
an Java interface as opposed to implementation class as a reference type?"
(This issue has been discussed in "Java interface" topic by the way.)

In general, you want to use Interface as opposed to an implementation
mainly because the implementation can change without affecting
the user of the interface, thus provides more flexible and agile
architecture.

-S


Thanks!

Fred.



--
-------------------------------------------------------------------
             Sang Shin, [email protected]
          Founder and Chief Instructor of JPassion.com
        JRebel/LiveRebel Evangelst from ZeroTurnaround.com
http://JPassion.com/portal/instructors/sang-shin-schedule (Bio)
          http://www.javapassion.com/webinars (Webinars)
         http://www.linkedin.com/in/javapassion (Linkedin)
          http://twitter.com/javapassion (Tweeter)
            Life is worth living... with Passion!
----------------------------------------------------------------------

--
You received this message because you are subscribed to the Google Groups 
"JPassion.com: Java Programming" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jpassion_java?hl=en.

Reply via email to