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


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

Re: Changing accessor on public static class

Newsgroups comp.lang.java.programmer
Date 2016-09-06 07:00 -0700
References <eb67e063-898b-4580-9c6f-18a8dae4d95a@googlegroups.com>
Message-ID <dd57e08f-04ae-4858-940c-9d2430212265@googlegroups.com> (permalink)
Subject Re: Changing accessor on public static class
From Eric Douglas <e.d.programmer@gmail.com>

Show all headers | View raw


On Tuesday, September 6, 2016 at 3:55:27 AM UTC-4, mike wrote:
> Hi,
> 
> I use this class from another library like this:
> 
> app.connect(new Configuration( ipAddress, username));
> 
> I tried to make class Configuration not public ( since I did not want to expose this name) and it can still be created.
> Is there any point in making it Configuration class not public?
> 
> static class Configuration
> 
> 
> br,
> 
> //mike
> 
> 
> public static class Configuration {
> 
>        
>         private String host;
>         private String username;
>       
>         
>         /**
>          * Constructor
>          * 
>          * @param host
>          * @param username
>          */
>         public Configuration( String host, String username) {  
>             this.host = host;
>             this.username = username;
>             
>         }
> 
>        
>         /**
>          * 
>          * @return host
>          */
>         public String getHost() {
>             return host;
>         }
>         /**
>          * 
>          * @return user name.
>          */
>         public String getUsername() {
>             return username;
>         }
>         
>        
>     }

Is there any point in making it public?
As Eric S said, a top-level class cannot be static, so we're assuming this is an inner class.  The only point to a static inner class is if you need an instance of it in a static method.  If your app.connect statement is in the outer class that contains this static class it can be a private class.  If you need other classes in the same package to reference it you can make it protected, and of course public allows everyone to use it, but of course they would refer to it as new OuterClass.Configuration().  You might as well limit it to the smallest scope if this is all there is to it.  Make it public if anything outside the outer class needs to configure it with anything other than what you want to pass through the outer class.

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


Thread

Changing accessor on public static class mike <mikaelpetterson@hotmail.com> - 2016-09-06 00:53 -0700
  Re: Changing accessor on public static class Alberto Salvati <zzzato@gmail.com> - 2016-09-06 01:12 -0700
  Re: Changing accessor on public static class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-09-06 09:08 -0400
    Re: Changing accessor on public static class Andreas Leitgeb <avl@logic.at> - 2016-09-06 23:00 +0000
      Re: Changing accessor on public static class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-09-07 07:48 -0400
  Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-06 07:00 -0700
    Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-06 19:31 -0400
      Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-07 04:47 -0700
        Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-07 18:52 -0400
          Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-08 04:54 -0700
            Re: Changing accessor on public static class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-09-08 08:38 -0400
              Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-08 06:35 -0700
                Re: Changing accessor on public static class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-09-08 10:09 -0400
                Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-08 08:18 -0700
                Re: Changing accessor on public static class Eric Douglas <e.d.programmer@gmail.com> - 2016-09-08 08:37 -0700
                Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-08 19:34 -0400
                Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-08 19:32 -0400
            Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-08 19:30 -0400
              Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-08 21:50 -0400
            Re: Changing accessor on public static class Lew <lewbloch@gmail.com> - 2016-09-13 17:44 -0700
    Re: Changing accessor on public static class Lew <lewbloch@gmail.com> - 2016-09-13 17:42 -0700
  Re: Changing accessor on public static class Arne Vajhøj <arne@vajhoej.dk> - 2016-09-06 19:33 -0400
  Re: Changing accessor on public static class Lew <lewbloch@gmail.com> - 2016-09-13 17:39 -0700

csiph-web