Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: How to assign an object to another in it method? Date: Sun, 2 Jul 2017 21:23:26 -0400 Organization: Aioe.org NNTP Server Lines: 37 Message-ID: References: <46334961-cc18-491f-828c-32e7401c7832@googlegroups.com> NNTP-Posting-Host: PBuS014lhzVyHjLbXmo/ZQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:36792 On 6/28/2017 8:51 AM, Eric Douglas wrote: > On Wednesday, June 28, 2017 at 8:24:54 AM UTC-4, Andreas Leitgeb wrote: >> Obviously, stuff shouldn't be exactly duplicated in multiple c'tor >> bodies, and doesn't need to, either, for reasons stated. > > public class MyClass > String var1; > public MyClass(){ > this("init"); > } > public MyClass(final String arg){ > var1=arg; > } > > Normally it's like this. Now if you were to put something in the no > arg constructor and something calls this one arg constructor with a > super(), that gets missed. I can't think of a case where you would > want 2 constructors doing something totally different that shouldn't > actually be 2 different classes. > The above is one reason - which is really the issue of Java formal parameters not supporting default values. But there are other reasons. One that comes to my mind is different input types carrying the same information. String(String original) String(char[] value) String(byte[] bytes, String charsetName) etc. comes to mind. Of course those are also tightly related. Arne