Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 11 Jul 2011 21:02:10 -0500 Date: Mon, 11 Jul 2011 19:02:01 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.help Subject: Re: Instantiation of a class References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 28 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 75.11.53.97 X-Trace: sv3-wgprsHXAmpZwOQzmxh0sQOYz1V50Db0YoTrcUhaWoCFBkT0irwYG6CxxxxheNTOr6MtSchB4e4gGQ4J!7nV4fVrEfTeIRIF2TvCX8aRFYRm5FeNxnmpgqWk1VXnD2CIicfGPjFwOkznJksBikTZ9CtBlFM/v!6TG0PVyFultbT4xNKeR0b9GDQWOWlJrVSm5GZCUgruM= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2028 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:849 On 7/11/2011 6:57 PM, Eric Sosman wrote: > On 7/11/2011 7:03 PM, Fred wrote: >> >> I'm thinking about statements like String foo = new String("foo"); >> When is the constructor specified not the name of the type of >> reference variable? > > Aside: The example is sort of silly, because one seldom needs > two instances of the same String. > > At the risk of answering a homework question, I can think of > two situations in which `x = new Y(...)' works even though x does > not have type Y. First, x's type may be that of one of Y's > superclasses, or of an interface implemented by Y. Second, the > class that's instantiated might not have a name the Java source > code can speak. > > And maybe the gurus will think of additional possibilities. > Unboxing: int x = new Integer(3); Yuck! Patricia