What languages ​​have properties that getters and setters can assign?

Java is not. (This is just a convention)

Delphi does. I believe C # does.

What other languages?

Edit: I should have given an example:

Delphi: (be careful, it has been a while, I could be wrong)

 type
   TSomething = class
   fEmployeeNum: String;
    property employeeNum: String read fEmployeeNum write setEmployeeNum;
   end;

 procedure TSomething.setEmployeeNum(var val: String);
 begin
   fEmployeeNum := val;
 end;

      

+1


a source to share


7 replies


Python does.

class SomeClass( object ):
def f_get( self ):
    return self.value
fprop = property( f_get )

      



The code for the setter is similar.

+3


a source


C # (just for example):



class Foo
{
    public string Bar { get; private set; }
    public string Bargain
    {
        get { return this._Bargain; }
        set { this._Bargain = value; }
    }
    private string _Bargain;
}

      

+3


a source


Ruby does through attr_reader

, attr_writer

and attr_accessor

(read / write):

class SomeClass
  attr_reader :foo #read-only
  attr_writer :bar #write-only
  attr_accessor :baz #read and write

  ...
end

      

+3


a source


VB.NET fulfills the Property keyword.

+1


a source


C ++ is not standard-compliant, but you can create bandwidth through templates.

+1


a source


target c and you can be lazy with the synthesize keyword.

0


a source


In Perl 6,

use v6;

sub foo() is rw {
    state $foo;
    return new Proxy:
        FETCH => method { return $foo },
        STORE => method($to) { $foo = $to };
}

foo = "Hello, world!";
say foo;

      

... at least in theory. Doesn't seem to work with Rakudo r38250.

0


a source







All Articles