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: Mon, 3 Jul 2017 08:38:45 -0400 Organization: Aioe.org NNTP Server Lines: 56 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:36794 On 7/3/2017 6:59 AM, Martin Gregorie wrote: > In practise, I often find myself doing something like this: > > public class Demo > { > private String name; > private int number; > private boolean prisoner; > > public Demo(String name, int answer, boolean prisoner) > { > this.name = name; > this.number = number; > this.isPrisoner = prisoner; > } > > public Demo(String name) > { > super(name, 6, true); > } > } > > ... and so on. > > IOW there's one constructor that can set all attributes that might be set > externally and a number of others that accept fewer arguments and set > appropriate defaults for the other attributes. Yes. That is what I consider the missing default parameter issue. In some languages: public Demo(String name, int answer, boolean prisoner) { this.name = name; this.number = number; this.isPrisoner = prisoner; } public Demo(String name) { super(name, 6, true); } can be made as: // **** NOT JAVA **** public Demo(String name, int answer = 6, boolean prisoner = false) { this.name = name; this.number = number; this.isPrisoner = prisoner; } Arne