如何使用class?

How to use a class?

我使用retrofit进行数据传输。我很困惑。 我让 Pojo 生成了 classes。但是我不知道如何使用 Destination class.

  public class NewOrderRequest {

    @SerializedName("phone")
    @Expose
    private String phone;

    public NewOrderRequest(String phone, List<Destination> destinations) 
    {
       super();
       this.phone = phone;
       this.destinations = destinations;
    }

    public String getPhone() {return phone;}

    public void setDestinations(List<Destination> destinations)
    {
    this.destinations = destinations;
    }

    }

CLASS 目的地:

public class Destination {

   @SerializedName("lat")
    @Expose
    private String lat;

    public Destination(String lat) {
    super();
    this.lat = lat;

    public String getLat() {
    return lat;
    }

    public void setLat(String lat) {
    this.lat = lat;
    }

    }

使用:

我应该将什么传递给 setDestination 方法?

    NewOrderRequest newOrderRequest = new NewOrderRequest();
    newOrderRequest.setPhone("+911");
    newOrderRequest.setDestinations(????????);


    NetworkService.getInstance()
                .service()
                .newOrder(jsessionid, newOrderRequest)

这是我试过的:

  List<Destination> destination = null;
        destination.add();

您需要创建一个 List<Destination。但是在您的尝试中,您只声明了 List,您从未创建过。试试这个:

List<Destination> destination = new ArrayList<>();
destination.add(new Destination("lat"));
newOrderRequest.setDestinations(destination);

您还需要

import java.util.ArrayList;