Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #21075
| X-Received | by 10.66.72.232 with SMTP id g8mr7839643pav.23.1357507298153; Sun, 06 Jan 2013 13:21:38 -0800 (PST) |
|---|---|
| Received | by 10.49.48.41 with SMTP id i9mr9873923qen.36.1357507298082; Sun, 06 Jan 2013 13:21:38 -0800 (PST) |
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.ripco.com!rahul.net!wasp.rahul.net!rahul.net!news.kjsl.com!usenet.stanford.edu!b8no2207967pbd.0!news-out.google.com!s9ni85391pbb.0!nntp.google.com!f6no9342483pbd.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.java.programmer |
| Date | Sun, 6 Jan 2013 13:21:37 -0800 (PST) |
| In-Reply-To | <50e9e786$0$290$14726298@news.sunsite.dk> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=50.14.119.173; posting-account=lPVJQwoAAACjT2AlnY0YSj2LC4j2qtwQ |
| NNTP-Posting-Host | 50.14.119.173 |
| References | <public-20130106091348@ram.dialup.fu-berlin.de> <a507821e-173c-447f-a310-bb98f425f097@googlegroups.com> <e1778471-c18f-46e6-9a7e-d7d312d684c3@googlegroups.com> <bdc51fed-5efc-4380-8162-6f4309155239@googlegroups.com> <8889b1c7-4198-4d54-8fbc-8fa0ef8608a3@googlegroups.com> <919a1e82-bb3d-409b-a3c6-a6fe8e09b1c5@googlegroups.com> <50e9e786$0$290$14726298@news.sunsite.dk> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <31c0e887-032a-4311-8b23-4ce7878cc4b1@googlegroups.com> (permalink) |
| Subject | Re: "Hello world!" without a public class? |
| From | "Aryeh M. Friedman" <Aryeh.Friedman@gmail.com> |
| Injection-Date | Sun, 06 Jan 2013 21:21:38 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Xref | csiph.com comp.lang.java.programmer:21075 |
Show key headers only | View raw
On Sunday, January 6, 2013 4:07:17 PM UTC-5, Arne Vajhøj wrote:
> On 1/6/2013 1:48 PM, Aryeh M. Friedman wrote:
>
> >Now that being said here is a good example of something that is easier
>
> to read then either (yes it does get compiled into something very close
>
> to inner classes [not nested if I remember the jargon correctly] but no
>
> where near as ugly):
>
> >
>
> > Foo.java:
>
> >
>
> > public enum Foo
>
> > {
>
> > ACK {
>
> > public void doSomething(SomeClass arg)
>
> > {
>
> > do what ever for ACK
>
> > }
>
> > },
>
> > BAR {
>
> > public void doSomething(SomeClass arg)
>
> > {
>
> > do what ever for BAR
>
> > }
>
> > }
>
> > }
>
> >
>
> > Fred.java:
>
> >
>
> > public class Fred
>
> > {
>
> > public void someMethod()
>
> > {
>
> > SomeClass sc=new SomeClass(...);
>
> > Foo[] arr=new Foo[]{ACK,BAR}; // typing this for this example so being lazy on syntax
>
> >
>
> > for(Foo elem:arr)
>
> > elem.doSomething(sc);
>
> > }
>
> > }
>
> >
>
> > and voila much more readable then putting a whole rats nest of stuff in the initialization of arr
>
> > }
>
> > }
>
>
>
> Given that the above is both unreadable and un-compilable, then ...
>
>
>
> Arne
Ok here is some actual working code that effectively does the same thing with the psedocode filled in (including the command lines):
% cat Foo.java
public enum Foo
{
ACK {
public String doSomething(String arg)
{
return "ACK: "+arg;
}
},
BAR {
public String doSomething(String arg)
{
return "BAR: "+arg;
}
};
public abstract String doSomething(String arg);
}
% cat Fred.java
public class Fred
{
public static void main(String[] args)
{
for(Foo elem:new Foo[]{Foo.ACK,Foo.BAR})
System.out.println(elem.doSomething("I am doing something"));
}
}
% javac Fred.java
% java Fred
ACK: I am doing something
BAR: I am doing something
Now please tell me that does not replace inner classes (the enum constants are compiled as inner classes and not just straight data constants).
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: "Hello world!" without a public class? "Aryeh M. Friedman" <Aryeh.Friedman@gmail.com> - 2013-01-06 02:10 -0800
Re: "Hello world!" without a public class? Lew <lewbloch@gmail.com> - 2013-01-06 09:43 -0800
Re: "Hello world!" without a public class? "Aryeh M. Friedman" <Aryeh.Friedman@gmail.com> - 2013-01-06 09:51 -0800
Re: "Hello world!" without a public class? Lew <lewbloch@gmail.com> - 2013-01-06 09:58 -0800
Re: "Hello world!" without a public class? "Aryeh M. Friedman" <Aryeh.Friedman@gmail.com> - 2013-01-06 10:48 -0800
Re: "Hello world!" without a public class? Arne Vajhøj <arne@vajhoej.dk> - 2013-01-06 16:07 -0500
Re: "Hello world!" without a public class? "Aryeh M. Friedman" <Aryeh.Friedman@gmail.com> - 2013-01-06 13:21 -0800
Re: "Hello world!" without a public class? Arne Vajhøj <arne@vajhoej.dk> - 2013-01-06 16:43 -0500
Re: "Hello world!" without a public class? Lew <lewbloch@gmail.com> - 2013-01-06 17:24 -0800
Re: "Hello world!" without a public class? Arne Vajhøj <arne@vajhoej.dk> - 2013-01-06 15:59 -0500
Re: "Hello world!" without a public class? "Aryeh M. Friedman" <Aryeh.Friedman@gmail.com> - 2013-01-06 13:22 -0800
Re: "Hello world!" without a public class? Arne Vajhøj <arne@vajhoej.dk> - 2013-01-06 16:35 -0500
csiph-web