简体   繁体   中英

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?

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM