Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #21095

Re: "Hello world!" without a public class?

Newsgroups comp.lang.java.programmer
Date 2013-01-06 17:24 -0800
References (1 earlier) <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>
Message-ID <53b5b13b-4baa-4c64-bead-404bf0073da4@googlegroups.com> (permalink)
Subject Re: "Hello world!" without a public class?
From Lew <lewbloch@gmail.com>

Show all headers | View raw


Aryeh M. Friedman wrote:
> On inner classes:
> ...
> (yes it does get compiled into something very close to inner classes [not nested if I remember the jargon correctly]

Terminology:  A nested type (class or interface) is a member of another type. 
(JLS §8.5)

There are two kinds of nested classes, static and inner, per the JLS. 
By definition, an inner class is a nested class whose declaration does not include the keyword 'static'.

"The static keyword may modify the declaration of a member type C within the 
body of a non-inner class or interface T. Its effect is to declare that C is 
not an inner class."
(JLS §8.5.1)

>  but no where near as ugly):

These get compiled exactly into inner classes.

> Foo.java:
> 
> public enum Foo
> {
>     ACK {

@Override

>        public void doSomething(SomeClass arg)
>        {
>           do what ever for ACK
>        }
>     },
> ...
> }

In this case the enum, itself a cover for compiler-supported boilerplate for a
class with static constant members, also covers for the boilerplate of inner 
class declarations in those constants.

Much as the lambdas I mentioned earlier cover for the boilerplate of inner-
class declarations of SAM interface implementations.

Neither of these work without inner classes, so your proposal to eliminate 
inner classes would break them.

> Fred.java:
> ...
> and voila much more readable then putting a whole rats nest of stuff in the initialization of arr

Perhaps, but it doesn't prove the point, because it relies on inner classes.

And your claim that it's "much more readable" is not really proven.

public abstract class Bar
{
  private final String rep;
  abstract public void doSomething(Some arg);
  private Bar(String r) 
  {
    this.rep = r;
  }
  public static final BAR = new Bar("BAR") 
    {
      @Override
      public void doSomething(Some arg) 
      { 
    //    do what ever for BAR 
      } 
    };
}

The only part of the anonymous class declaration that differs is the 

new Bar("BAR") 

Not even "much" different in readability, let alone "very much".

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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