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


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

Re: Java variable access

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: Java variable access
Date 2019-04-12 10:35 -0400
Organization Aioe.org NNTP Server
Message-ID <q8q7n6$13f6$1@gioia.aioe.org> (permalink)
References <109a7224-f392-46c3-bf56-7d8bf2bfb4bf@googlegroups.com> <q8q60r$rcu$1@gioia.aioe.org> <2a9f711b-78f4-483b-a94d-d7bb86434f1f@googlegroups.com>

Show all headers | View raw


On 4/12/2019 10:23 AM, Eric Douglas wrote:
> On Friday, April 12, 2019 at 10:06:30 AM UTC-4, Arne Vajhøj wrote:
>> I would use field + getter + maybe setter.
>>
>> The advantages I see are:
>> A) The ability to have no setter which controls what can change
>>      the value
>> B) The ability to override getter and setter in sub classes
>> C) The ability to put more code in getter and setter
>>
>> It is not much work to add the getters and maybe setters as
>> a modern IDE should be able to generate those.
>>
>> If you don't like to see all these lines of code then
>> switch to Kotlin.
>>
>> :-)
> 
> That was my thought, to stick with all private/protected variables.
> Though it does just look cluttered if you end up with a lot of
> getters and setters, it does add more flexibility.  So when (if
> ever?) would you declare a class variable public, aside from the
> static final constants?

Practically never.

I cannot remember any need.

There are probably some exception, but ...

Arne


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


Thread

Java variable access Eric Douglas <e.d.programmer@gmail.com> - 2019-04-12 06:57 -0700
  Re: Java variable access Arne Vajhøj <arne@vajhoej.dk> - 2019-04-12 10:06 -0400
    Re: Java variable access Eric Douglas <e.d.programmer@gmail.com> - 2019-04-12 07:23 -0700
      Re: Java variable access Arne Vajhøj <arne@vajhoej.dk> - 2019-04-12 10:35 -0400
      Re: Java variable access Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-04-12 10:58 -0400
        Re: Java variable access Eric Douglas <e.d.programmer@gmail.com> - 2019-04-12 08:31 -0700
          Re: Java variable access Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-04-12 14:40 -0400
        Re: Java variable access Arne Vajhøj <arne@vajhoej.dk> - 2019-04-12 12:31 -0400
  Re: Java variable access Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-04-12 10:56 -0400
  Re: Java variable access Joerg Meier <joergmmeier@arcor.de> - 2019-04-12 23:11 +0200
    Re: Java variable access Arne Vajhøj <arne@vajhoej.dk> - 2019-04-12 21:51 -0400
      Re: Java variable access Joerg Meier <joergmmeier@arcor.de> - 2019-04-13 21:59 +0200
        Re: Java variable access Arne Vajhøj <arne@vajhoej.dk> - 2019-04-13 18:38 -0400
          Re: Java variable access Joerg Meier <joergmmeier@arcor.de> - 2019-04-16 22:08 +0200
            Re: Java variable access Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-04-16 16:46 -0400
              Re: Java variable access Joerg Meier <joergmmeier@arcor.de> - 2019-04-16 23:01 +0200
              Re: Java variable access Eric Douglas <e.d.programmer@gmail.com> - 2019-04-17 06:42 -0700
                Re: Java variable access Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-04-17 21:35 +0200
                Re: Java variable access Eric Douglas <e.d.programmer@gmail.com> - 2019-04-17 14:05 -0700
                Re: Java variable access Joerg Meier <joergmmeier@arcor.de> - 2019-04-19 10:40 +0200
                Re: Java variable access Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-04-19 17:20 -0400

csiph-web