Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38657
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Overloading methods question |
| Date | 2018-10-25 21:42 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <pqtrdv$mu8$1@gioia.aioe.org> (permalink) |
| References | (3 earlier) <75ad8b55-3def-4ec1-b46b-65ecd971d0fe@googlegroups.com> <pqtdpa$nl4$1@dont-email.me> <pqtg50$ga7$1@news.albasani.net> <pqtluk$gg9$1@gioia.aioe.org> <pqtnjm$abo$1@news.albasani.net> |
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 I am not sure that I can follow that argument. If you make the enum nested instead of top level then it will be in the same source file at the same place as the int constants would have been. And in the java docs you just click on the type to get to the java docs instead of scrolling around searching for info you need. >> 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. public void foobar(MyEnum val) is simpler than: /** * ... * Note: val takes the values SomeClass.Const1, ..., SomeClass.Constn */ public void foobar(int val) >> And enum is type safe while int constants are not. >> > AFAIK that is not relevant if the constant is defined as static final. It is as the example shown. >> 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. Yes. But that is a runtime error instead of a compile time error. Moving errors from runtime to compile time is what type safety is all about. And many people (but not all) consider doing that a good thing. Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Overloading methods question Rhino <no_offline_contact@example.com> - 2018-10-24 17:04 -0400
Re: Overloading methods question Arne Vajhøj <arne@vajhoej.dk> - 2018-10-24 18:56 -0400
Re: Overloading methods question Joerg Meier <joergmmeier@arcor.de> - 2018-10-25 10:13 +0200
Re: Overloading methods question Rhino <no_offline_contact@example.com> - 2018-10-25 15:53 -0400
Re: Overloading methods question Eric Douglas <e.d.programmer@gmail.com> - 2018-10-25 13:58 -0700
Re: Overloading methods question Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-10-25 17:49 -0400
Re: Overloading methods question Martin Gregorie <martin@mydomain.invalid> - 2018-10-25 22:29 +0000
Re: Overloading methods question Arne Vajhøj <arne@vajhoej.dk> - 2018-10-25 20:08 -0400
Re: Overloading methods question Martin Gregorie <martin@mydomain.invalid> - 2018-10-26 00:37 +0000
Re: Overloading methods question Arne Vajhøj <arne@vajhoej.dk> - 2018-10-25 21:42 -0400
Re: Overloading methods question Joerg Meier <joergmmeier@arcor.de> - 2018-10-26 12:46 +0200
Re: Overloading methods question Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-10-26 07:50 -0400
Re: Overloading methods question Martin Gregorie <martin@mydomain.invalid> - 2018-10-26 19:33 +0000
Re: Overloading methods question Eric Douglas <e.d.programmer@gmail.com> - 2018-10-26 13:13 -0700
Re: Overloading methods question Arne Vajhøj <arne@vajhoej.dk> - 2018-10-26 20:58 -0400
Re: Overloading methods question Martin Gregorie <martin@mydomain.invalid> - 2018-10-27 22:36 +0000
Re: Overloading methods question Arne Vajhøj <arne@vajhoej.dk> - 2018-10-27 19:38 -0400
Re: Overloading methods question Martin Gregorie <martin@mydomain.invalid> - 2018-10-28 10:39 +0000
Re: Overloading methods question Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-10-28 07:54 -0400
Re: Overloading methods question Eric Douglas <e.d.programmer@gmail.com> - 2018-10-26 06:26 -0700
Re: Overloading methods question Joerg Meier <joergmmeier@arcor.de> - 2018-10-26 12:52 +0200
Re: Overloading methods question Rhino <no_offline_contact@example.com> - 2018-10-26 22:10 -0400
Re: Overloading methods question Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-10-27 07:43 -0400
Re: Overloading methods question Rhino <no_offline_contact@example.com> - 2018-10-29 14:40 -0400
Re: Overloading methods question Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-10-29 16:39 -0400
Re: Overloading methods question Eric Douglas <e.d.programmer@gmail.com> - 2018-10-29 05:07 -0700
Re: Overloading methods question Rhino <no_offline_contact@example.com> - 2018-10-29 14:41 -0400
Re: Overloading methods question Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-10-25 07:49 -0400
Re: Overloading methods question Rhino <no_offline_contact@example.com> - 2018-10-25 16:07 -0400
csiph-web