-2

What is getter and setter in android development.

And what is the use of @Expose in GSON.

@SerializedName("url")
    @Expose
    private String url;
SUMIT KUMAR
  • 153
  • 1
  • 1
  • 10

2 Answers2

0

Getter = accessing variable to be able to use

Setter = assigning a new value to variable

@Expose is used to decide whether a variable will be exposed for serialization/deserialization or not

Zafer Celaloglu
  • 1,438
  • 1
  • 17
  • 28
0

In Java, getter and setter are two conventional methods that are used for retrieving and updating value of a variable.

Something like:

public class Example {
    private int number;

    public int getNumber() {
        return this.number;
    }

    public void setNumber(int number) {
        this.number = number;
    }
}

@Expose is an annotation. The official doc:

An annotation that indicates this member should be exposed for JSON serialization or deserialization.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841