Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Overloading methods question Date: Fri, 26 Oct 2018 07:50:34 -0400 Organization: A noiseless patient Spider Lines: 54 Message-ID: References: <1b2bqd7oqzez6$.sfpve8lwmic2.dlg@40tude.net> <75ad8b55-3def-4ec1-b46b-65ecd971d0fe@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 26 Oct 2018 11:50:37 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="e77f855eb6b8bfcabb3711d5a35397bd"; logging-data="6946"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vOx9DgZB+AEIK8ebC0Ox0" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 Cancel-Lock: sha1:/ZwPiXFQGmC3votv0eEJf9j+UxQ= In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:38660 On 10/25/2018 8:37 PM, Martin Gregorie wrote: > On Thu, 25 Oct 2018 20:08:54 -0400, Arne Vajhøj wrote: > >> Enum achives the same 4 goals (except obviously the first half of #a - >> not having to define an enum). >> > Sure, though being defined outside a class that is the only place its > used (apart from when its supplied as a method argument) as we've been > discussing does separate each constant definition and its documentation > from the class definition and documentation public class Whatnot { public static enum Style { LONG, SHORT }; ... String method(Style style) { ... } } Whatnot what = new Whatnot(); String thing = what.method(Whatnot.Style.SHORT); >> And enum will be better/easier documented for method arguments. >> > Apart from the separation mentioned above. I see this as a disadvantage > though you may not. "Better/easier" is a *dis*advantage? Is this Opposite Day? >> And enum is type safe while int constants are not. >> > AFAIK that is not relevant if the constant is defined as static final. Both Arne's and Martin's comments elude my understanding, so I won't try to respond. >> will be accepted by the compiler but have undefined semantics. >> > Agreed, but being basically a mildly paranoid C programmer I tend to > validate all arguments, including those created with a #define (C) or as > static final int (Java) and you really shouldn't be defining a constant > unless its one of the above or part of an enum. Early mistake detection beats late misteak detectoin, every time. Compile-time detection beats run-time detection. > So far, it all looks a bit like swings and roundabouts to me except, of > course, if your enum contains logic rather than being simply a list of > constants. My scorecard shows Arne with three, Martin with nil, and one undecided. -- esosman@comcast-dot-net.invalid Eight hundred seventeen days to go.