0

I have visited many references regarding the simple question - how to declare a property under Android Java. All of the examples I found do not eliminate compiler's errors.. Please, help me to save my time, give me the analog of the C# properties but under Android Java.

Class A {
    protected bool bField = false;
    public bool BField { get { return bField; } set { bField = value; }

// and

    public bool AField { get; set; }

}

Thanks

1 Answers1

1

There are no "properties" in Java (not as far as the compiler is concerned, anyway). A C# property translates into 3 three things in Java - a private field, a getter and a setter method.

So a property like this in C#:

public bool AField { get; set; }

would translate to the following in Java:

private boolean aField;

public boolean getAField() { return aField; }

public void setAField(boolean aField) { this.aField = aField; }

(Actually, for a boolean field, the getter usually has the prefix is, e.g. isHidden, isEnabled etc. but here isAField sounds weird)

Sweeper
  • 213,210
  • 22
  • 193
  • 313
  • hi..Sweeper ..can you help me out her -->https://stackoverflow.com/questions/59526045/how-to-run-java-and-xml-code-fetched-from-api-into-another-fragment – Wini Jan 01 '20 at 08:09