user3170491
user3170491

Reputation: 33

What is the purpose of this(); in this context

Consider the following code:

    public Fingerprint(HashMap<String, Integer> measurements) {
        this();
        mMeasurements = measurements;
    }

   public Fingerprint(HashMap<String, Integer> measurements, String map) {
        this(measurements);
        mMap = map;
    }

    public Fingerprint(int id, String map, PointF location) {
        this();
        mLocation = location;
    }

    public Fingerprint(int id, String map, PointF location, HashMap<String, Integer> measurements) {
        this(id, map, location);
        mMeasurements = measurements;
    }

what is the purpose of this(); in this context? Since I have the idea that "this" refers to the fields of the current object. is it the same definition here?

Upvotes: 0

Views: 4558

Answers (1)

rgettman
rgettman

Reputation: 178303

Calling this(); as if it were a method is the way to invoke another constructor from within a constructor. You are effectively calling Fingerprint().

Please see the Java Tutorial on the subject, section "Using this with a Constructor".

Upvotes: 6

Related Questions